JS實現(xiàn)物體帶緩沖的間歇運動效果示例
更新時間:2016年12月22日 09:40:07 作者:hcjavascript
這篇文章主要介紹了JS實現(xiàn)物體帶緩沖的間歇運動效果,可實現(xiàn)物體定時間歇運動的功能,涉及javascript定時器、數(shù)學運算及頁面元素動態(tài)修改的相關操作技巧,需要的朋友可以參考下
本文實例講述了JS實現(xiàn)物體帶緩沖的間歇運動效果。分享給大家供大家參考,具體如下:
<!DOCTYPE HTML> <html> <head> <meta http-equiv="content-type" charset="utf-8" /> <meta http-equiv="content-type" content="text/html" /> <title>demo</title> </head> <body> <div id="odiv" style="position:absolute;width:200px;height:100px;background:red;left:0;border:1px solid #333;"></div> <script type="text/javascript"> var odiv=document.getElementById('odiv'); odiv.onmouseover=function(){ move(this,'width',500,function(){ move(odiv,'left',300,function(){ move(odiv,'height',500,function(){ move(odiv,'borderWidth',10) }); }); }); } function move(obj,arr,target,fn){ clearInterval(obj.dt); obj.dt=setInterval(function(){ obj.ol=parseInt(obj.style[arr]); if(obj.ol==target){ clearInterval(obj.dt); if(fn) fn(); }else{ obj.speed=(target-obj.ol)/8; obj.speed>0?obj.speed=Math.ceil(obj.speed):obj.speed=Math.floor(obj.speed); obj.style[arr]=obj.ol+obj.speed+"px"; } },30); } </script> </body> </html>
更多關于JavaScript相關內容感興趣的讀者可查看本站專題:《JavaScript運動效果與技巧匯總》、《JavaScript切換特效與技巧總結》、《JavaScript查找算法技巧總結》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調試技巧總結》、《JavaScript數(shù)據(jù)結構與算法技巧總結》、《JavaScript遍歷算法與技巧總結》及《JavaScript數(shù)學運算用法總結》
希望本文所述對大家JavaScript程序設計有所幫助。
相關文章
JavaScript實現(xiàn)垂直向上無縫滾動特效代碼
下面小編就為大家?guī)硪黄狫avaScript實現(xiàn)垂直向上無縫滾動特效代碼。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11