DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> javascript實現點擊按鈕讓DIV層彈性移動的方法
javascript實現點擊按鈕讓DIV層彈性移動的方法
編輯:關於JavaScript     

本文實例講述了javascript實現點擊按鈕讓DIV層彈性移動的方法。分享給大家供大家參考。具體實現方法如下:

復制代碼 代碼如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>點擊按鈕讓DIV層彈性移動特效</title>
<style type="text/css">
#div1{ background: #FFCC66; border:#FF6600 1px solid; height:100px; width:100px; position:relative; left:0px;}
</style>
<script type="text/javascript">
 var t=null;
 function startMove()
 {
  if(t)
  {
   clearInterval(t);
  }
  t=setInterval(move, 30);
 }
 var step=0;
 function move()
 {
  var odiv=document.getElementById("div1");
   step+=(100-odiv.offsetLeft)/50;
   step=step*0.98
  odiv.style.left=odiv.offsetLeft+step;
 }
</script>
</head>
<body>
<div id="div1">
</div>
<input type="button" value="移動" onclick="startMove()"/>
</body>
</html>

希望本文所述對大家的javascript程序設計有所幫助。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved