Utilizing two functions to apply a Fade In/Fade Out effect on an element. Confident in the functionality of both functions, as testing them sequentially in the Console proves their effectiveness.
However, executing:
fadeIn()
fadeOut()
seems to result in both operations occurring simultaneously.
function fadeIn(el) {
el.style.opacity = 0;
el.style.display = 'block';
var tick = function() {
el.style.opacity = +el.style.opacity + 0.01;
if (+el.style.opacity < 1) {
(window.requestAnimationFrame && requestAnimationFrame(tick)) || setTimeout(tick, 2500)
}
};
tick();
}
function fadeOut(el) {
el.style.opacity = 1;
var tickOut = function() {
el.style.opacity = +el.style.opacity - 0.01;
if (+el.style.opacity > 0) {
(window.requestAnimationFrame && requestAnimationFrame(tickOut)) || setTimeout(tickOut, 2500)
}
else if (+el.style.opacity === 0){
el.style.display = 'none';
}
};
tickOut();
}
Access JsFiddle link here: https://jsfiddle.net/cwu9sg3h/
Edit: Intended outcome involves quote fading in, followed by a fade out, transitioning to another quote with the same effect. Process is set to rotate quotes continuously.
Edit #2: jQuery not viable for this specific project!