0
Hello, I’m having trouble reset to 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 didn’t work, when I implement the third "if
" in the fade out function, the opacity drops, but instead of going to 0
, go to 0,99
, how do I solve the problem?
return function() {
 window[fn](h, 1000);
 }
can explain me this line sff– Miguel
@Miguel This line is only to make the example work. How I define the functions in the global scope they are accessible via
window
. When I gave the sameid
to the buttons as the names of the functions, I did so to make the click on the button invoke the respective function.– Sergio
Thank you @Sergio
– Miguel
@Sergio thanks so much for your help :)
– Diogo Miranda
@You are welcome. If you have solved your problem you can mark the answer as accepted.
– Sergio