Hello, I'm having trouble resetting setInterval () in 2 functions, they have to be re-used in the affected Ids
Here is the JS code:
//Fuction Fade out
function fadeOut(elem, speed) {
if (!elem.style.opacity) {
elem.style.opacity = 1;
}
if (elem.style.opacity >= 1) {
setInterval(function() {
if (elem.style.opacity >= 0) {
elem.style.opacity = parseFloat(elem.style.opacity) - 0.03;
}
}, speed / 50);
if (elem.style.opacity >= 1) {
clearInterval(0);
}
}
}
//Função fade in
function fadeIn(elem, speed) {
if (!elem.style.opacity) {
elem.style.opacity = 0;
}
/*var timerId=*/
if (elem.style.opacity <= 0) {
setInterval(function() {
if (elem.style.opacity <= 1) {
elem.style.opacity = parseFloat(elem.style.opacity) + 0.03;
}
}, speed / 50);
}
/*if(elem.style.opacity >="1"){
clearInterval(timerId);
return;} */
}
PS: I tried to solve my problem with a while
, but it did not work, when I put the third " if
" in the fade out function, the opacity decreases, but instead of going to 0
, it goes to 0,99
, how do I solve the problem?