javascript實現圖片的移動

<html>
 <head>
  <title>test</title>
  <meta http-equiv='Content-Language' content='zh-cn' /><meta http-equiv='content-type' content='text/html; charset=UTF-8' />
  <script>
  var xp=0;
  var moveTimer;
  function move(){
   xp=xp+5;  //位移的大小
   document.getElementById('moveObj').style.left=xp+'px';//移動的方向;
   if(xp>=1000)
    clearInterval(moveTimer);//移動的距離;
  }
  window.οnlοad=function(){ moveTimer=setInterval(move,2);} //移動的速度;
  </script>
 </head>
 <body>
  <div id="moveObj" style="height:120px;width:230px;background-color:red;position:absolute;left:0;top:0"></div>
 </body>
</html>
發佈了37 篇原創文章 · 獲贊 9 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章