Javascript在函数中设置不透明度 功能衰减(obj,时间){ if(this){//防止函数一次调用太多次 addCallData(本); } 如果(!obj | |!时间){ 警报(“需要对象/时间参数。\n”); 返回false; }否则{ 如果(!func_data[this][“fade”]){/*如果没有为[this]定义淡入淡出,则定义它*/ func_数据[this][“fade”]=((obj.style.opacity)?1:(obj.style.filter)); }否则{ 如果(功能数据[此][“淡入”]
检查此项:Javascript在函数中设置不透明度 功能衰减(obj,时间){ if(this){//防止函数一次调用太多次 addCallData(本); } 如果(!obj | |!时间){ 警报(“需要对象/时间参数。\n”); 返回false; }否则{ 如果(!func_data[this][“fade”]){/*如果没有为[this]定义淡入淡出,则定义它*/ func_数据[this][“fade”]=((obj.style.opacity)?1:(obj.style.filter)); }否则{ 如果(功能数据[此][“淡入”],javascript,html,css,Javascript,Html,Css,检查此项: 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;
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*/
}
}
}
函数setOpacity(值){
testObj.style.opacity=值/10;
testObj.style.filter='alpha(不透明度='+value*10+');
}
参考资料:@DrStrangeLove它不起作用。如果(这个)是完全无用的。
这个
总是被强制成总是真实的对象。@pimvdb你能提供一个澄清吗?如果(这个)
总是会通过的,因为这个
总是有意义的。所以你可以消除如果(这个){
和}
。那么我应该如何引用刚刚调用的函数/对象而不使用[if(this){}]?这也不起作用(y在全局范围内):函数淡入淡出(obj,time){if(y
function setOpacity(value) {
testObj.style.opacity = value/10;
testObj.style.filter = 'alpha(opacity=' + value*10 + ')';
}