亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JS單線程和完美運動框架的多定時器

JS單線程和完美運動框架的多定時器

John_Wang 2016-01-19 10:48:22
//最終封裝的'完美移動框架' function?startMove(obj,json,fn){ var?flag=true;//標志所有運動是否到達目標值 clearInterval(obj.timer); obj.timer=setInterval(function(){ for(var?attr?in?json){ var?curr=0; //判斷是否為透明度 if(attr=='opacity'){ curr=Math.round(parseFloat(getStyle(obj,attr))*100); }else{ curr=parseInt(getStyle(obj,attr)); } //移動速度處理 var?speed=0; speed=(json[attr]-curr)/10; speed=speed>0?Math.ceil(speed):Math.floor(speed); if(curr!=json[attr]){ flag=false; } if?(attr=='opacity')?{ obj.style.filter='alpha(opacity:'+(curr+speed)+")"; obj.style.opacity=(curr+speed)/100; }else{ obj.style[attr]=curr+speed+'px'; } } if(flag){ clearInterval(obj.timer); if(fn){ fu(); } } },30); } //取樣式 function?getStyle(obj,attr){ if(obj.currentStyle){//IE取樣式 return?obj.currentStyle[attr]; }else{ return?getComputedStyle(obj,false)[attr]; } }
查看完整描述

1 回答

?
魂魄之子

TA貢獻5條經驗 獲得超0個贊

最后的函數名fn寫錯了

查看完整回答
反對 回復 2018-10-21
  • 1 回答
  • 0 關注
  • 1659 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號