使用setInterval实现渐隐藏

xiaoxiao2021-02-28  83

//使用setInterval实现渐隐藏 function myFadeout(ele){ var target = 1, speed = 1/50; var timer = setInterval(function(){ if(!parseFloat(ele.style.opacity) > 0){ ele.style.opacity = 1; } if(target>0){ target -= speed; ele.style.opacity = target; }else{ ele.style.opacity = 0; clearInterval(timer); } }, 20); }

调用:ele为已经获取到的HTML元素,

ele=document.getElementById('x');

转载请注明原文地址: https://www.6miu.com/read-72219.html

最新回复(0)