JS實現(xiàn)物體帶緩沖的間歇運動效果示例
本文實例講述了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>
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript運動效果與技巧匯總》、《JavaScript切換特效與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript動畫特效與技巧匯總》、《JavaScript錯誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學運算用法總結(jié)》
希望本文所述對大家JavaScript程序設(shè)計有所幫助。
相關(guān)文章
JavaScript實現(xiàn)垂直向上無縫滾動特效代碼
下面小編就為大家?guī)硪黄狫avaScript實現(xiàn)垂直向上無縫滾動特效代碼。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11