【发布时间】:2013-08-13 04:12:24
【问题描述】:
var faderout = function(){
if(foo.style.opacity>0){
foo.style.opacity -= 0.1;
var t = setTimeout(faderout,100);
}
else if(foo.style.opacity == 0){
o = true;
clearTimeout(t);
}
我无法将不透明度精确到 0,我只是将其设置为 0.1000000004,有谁知道我为什么不将其设置为 0?
【问题讨论】:
-
这就是浮点数的行为方式。stackoverflow.com/questions/1458633/…
-
为什么不丢掉 'else if' 并用 'else' 代替。另外,我建议只复制 fadeOut() 函数的 jQuery 源代码。无需重新发明轮子。
标签: javascript opacity fadeout