在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

为什么不能写成obj.currentStyle[attr] || getComputedStyle(obj, false)[a

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)
}

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖
国内首家创新型IT技术需求众包服务平台,软件需求就上天盟网! 立即登录 立即注册