window.onload=function(){ ? ?var aDiv=document.getElementsByTagName('div');? ? ? aDiv[2].onclick=function(){ ? ? ? ?startMove(this,"opacity",100) ? ?}}function startMove(obj, attr, iTarget){ ? ?clearInterval(obj.timer); ? ?obj.timer=setInterval(function (){ ? ? ? var iCur=0; ? ? ? ?var t=obj.currentStyle[attr]||getComputedStyle(obj, false)[attr]; ? ? ? ?if(attr=="opacity"){ ? ? ? ? ? ?iCur=parseInt(parseFloat(t)*100) ? ? ? ?} ? ? ? ?else{ ? ? ? ? ? ?iCur=parseInt(t); ? ? ? ?} ? ? ? ?var iSpeed=(iTarget-iCur)/8; ? ? ? ?iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed); ? ? ? ?if(iCur==iTarget) ? ? ? ?{ ? ? ? ? ? ?clearInterval(obj.timer); ? ? ? ?} ? ? ? ?else ? ? ? ?{ ? ? ? ? ? ?if(attr=="opacity"){ ? ? ? ? ? ? ? ?obj.style.filter="alpha(opacity:"+(iCur+iSpeed)+")"; ? ? ? ? ? ? ? ?obj.style[attr]=(iCur+iSpeed)/100; ? ? ? ? ? ?} ? ? ? ? ? ?else{ ? ? ? ? ? ? ? ?obj.style[attr]=iCur+iSpeed+'px'; ? ? ? ? ? ?} ? ? ? ?} ? ?}, 30)}
為什么不能寫成obj.currentStyle[attr] || getComputedStyle(obj, false)[attr];
慕田峪8701529
2017-08-23 22:25:00