帮忙解释这段代码的作用~!
- JScript code
function css(obj, attr, value){ if(arguments.length==2) return parseFloat(obj.currentStyle?obj.currentStyle[attr]:document.defaultView.getComputedStyle(obj, false)[attr]); else if(arguments.length==3) switch(attr) { case 'width': case 'height': case 'paddingLeft': case 'paddingTop': case 'paddingRight': case 'paddingBottom': value=Math.max(value,0); case 'left': case 'top': case 'marginLeft': case 'marginTop': case 'marginRight': case 'marginBottom': obj.style[attr]=value+'px'; break; case 'opacity': obj.style.filter="alpha(opacity:"+value*100+")"; obj.style.opacity=value; break; default: obj.style[attr]=value; } return function (attr_in, value_in){css(obj, attr_in, value_in)};}
偶正在自学JS,在研究别人的运动效果的时候,
看到这段代码,不明白是起什么作用的,
麻烦解释一下,谢谢了哈,
最好详细一点
[解决办法]
是因为调用css后又返回了一个函数,而这个返回函数又调用css函数,这样就形成了一个循环,可以无限次
作用就是上面写的那样,一行代码给多个属性赋值(每多一个括号都多调用了一次函数),看代码应该不难明白的