javascript 緩沖運動框架的實現
框架的使用,大大的提高了我們的編碼的效率,下面分享一個緩沖運動框架。
實例代碼:
/** * Created by wang on 2016/8/3. *///獲取非行間樣式和行間樣式function getStyle(obj,name) { if(obj.currentStyle){ return obj.currentStyle[name]; } else { return getComputedStyle(obj,false)[name]; }}//獲取非行間樣式和行間樣式//緩沖運動框架var timer=null;function startMove(obj,attr,iTarget) { clearInterval(obj.timer); obj.timer=setInterval(function () { var cur=0; if(attr=='opacity'){ cur=Math.round(parseFloat(getStyle(obj,attr))*100); } else { cur=parseInt(getStyle(obj,attr)); } var speed=(iTarget-cur)/6; speed=speed>0?Math.ceil(speed):Math.floor(speed); if(cur==iTarget){ clearInterval(timer); } else { if(attr=='opacity'){ obj.style.filter='alpha(opcity:'+(cur+speed)+')'; obj.style.opacity=(cur+speed)/100; } else { obj.style[attr]=cur+speed+'px'; } } },30)}//緩沖運動框架如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答