<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文檔</title> <style> #div1 {width:150px;height:200px;background:blue;left:-150px;top:100px;position:absolute;} #div1 span{width:25px;height:50px;position:absolute;left:150px;top:75px;background:yellow;line-height:25x;} </style> <script> window. () { var oDiv=document.getElementById('div1'); oDiv. () { startMove(0); }; oDiv. () { startMove(-150); }; }; var timer=null; function startMove(n1) { var oDiv=document.getElementById('div1'); clearInterval(timer); timer=setInterval(function () { var speed=0; //判斷變框所處位置相對于目標位置,從而賦值速度大小 if(oDiv.offsetLeft>n1) { speed=-10; } else { speed=10; } if(oDiv.offsetLeft==n1) { clearInterval(timer); } else { oDiv.style.left=oDiv.offsetLeft+speed+'px'; } },30); }; </script> </head> <body> <div id="div1"> <span>分享</span> </div> </body> </html>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。