function fade(obj, time) {
if(this) { //prevents the function from being called too many times at once
addCallData(this);
}
if(!obj || !time) {
alert("Object/time parameters are required.\n");
return false;
} else {
if(!func_data[this]["fade"]) { /*if fade is not defined for [this], then define it*/
func_data[this]["fade"] = ((obj.style.opacity)?1:(obj.style.filter));
} else {
if(func_data[this]["fade"] <= 0) { /*if object opacity has declined completely, then hide/remove the element to indicate that the object has faded*/
obj.style.display="none";
return false;
}
func_data[this]["fade"]=((func_data[this]["fade"])--); /*gradually reduce fade*/
((obj.style.filter)?((obj.style.filter)=func_data[this]["fade"]):
(obj.style.filter("alpha(opacity="+(func_data[this]["fade"])+""))); /*ultimately, set opacity to x-0.1 or x-1*/
setTimeout(function(){fade(obj, time);}, time); /*loop until false occurs*/
}
}
}
我不完全确定为什么这不起作用。我可以将func_data[this]["fade"]
设置为0.50,HTML元素将失去其不透明度的50%,但如果我将该属性的值设置为不透明度,该函数将停在那里并且不会达到超时阶段。
答案 0 :(得分:0)
检查一下:
function setOpacity(value) { testObj.style.opacity = value/10; testObj.style.filter = 'alpha(opacity=' + value*10 + ')'; }