javascript實現(xiàn)點擊按鈕讓DIV層彈性移動的方法
更新時間:2015年02月24日 15:39:32 作者:代碼家園
這篇文章主要介紹了javascript實現(xiàn)點擊按鈕讓DIV層彈性移動的方法,實例分析了javascript操作div層的操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了javascript實現(xiàn)點擊按鈕讓DIV層彈性移動的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
復制代碼 代碼如下:
<!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>
<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程序設(shè)計有所幫助。
您可能感興趣的文章:
相關(guān)文章
淺析JavaScript中的變量復制、參數(shù)傳遞和作用域鏈
這篇文章主要介紹了淺析JavaScript中的變量復制、參數(shù)傳遞和作用域鏈 的相關(guān)資料,需要的朋友可以參考下2016-01-01
javascript宿主對象之window.navigator詳解
這篇文章主要為大家詳細介紹了javascript宿主對象之window.navigator,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-09-09
JScript|Event]面向事件驅(qū)動的編程(二)--實例講解:將span模擬成超連接
JScript|Event]面向事件驅(qū)動的編程(二)--實例講解:將span模擬成超連接...2007-01-01

