javascript - Reset SetInterval to repeat the function on another ID -
im having trouble reseting setinterval() on 2 functions, suposed reused affected ids
heres javascript:
//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;} */ }
i have tried while fix problem, didn't help, when implement third "if" on fadeout function, opacity valor goes down, instead of going 0, goes 0,99. can do?
the clearinterval
needs name of interval clear think, need name put interval in variable :
var myinterval = setinterval(function(){ if(elem.style.opacity >=0){ elem.style.opacity = parsefloat(elem.style.opacity) - 0.03; } }, speed /50);
then ca clear :
clearinterval(myinterval);
Comments
Post a Comment