我有一个函数,在页面加载时淡化一个具有
id="box"
的正方形框。我尝试过,但未能找到如何再次淡入框或仅使用纯JavaScript淡入框或元素的方法(而非使用jQuery)。
这是我的fadeOut()
函数代码:var box = document.getElementById('box');
function fadeOut(elem, speed)
{
if(!elem.style.opacity)
{
elem.style.opacity = 1;
}
setInterval(function(){
elem.style.opacity -= 0.02;
}, speed /50);
}
fadeOut(box, 2000);
#box
{
width: 100px;
height: 100px;
background-color: blue;
}
<div id="box"></div>
非常感谢所有的贡献者。谢谢!