javascript實(shí)現(xiàn)點(diǎn)擊按鈕讓DIV層彈性移動的方法
更新時間:2015年02月24日 15:39:32 作者:代碼家園
這篇文章主要介紹了javascript實(shí)現(xiàn)點(diǎn)擊按鈕讓DIV層彈性移動的方法,實(shí)例分析了javascript操作div層的操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實(shí)例講述了javascript實(shí)現(xiàn)點(diǎn)擊按鈕讓DIV層彈性移動的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
復(fù)制代碼 代碼如下:
<!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>點(diǎn)擊按鈕讓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>點(diǎn)擊按鈕讓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è)計有所幫助。
您可能感興趣的文章:
- js實(shí)現(xiàn)鍵盤控制DIV移動的方法
- js+html+css實(shí)現(xiàn)鼠標(biāo)移動div實(shí)例
- 利用javascript移動div層-javascript 拖動層
- javascript DIV實(shí)現(xiàn)跟隨鼠標(biāo)移動
- JavaScript與Div對層定位和移動獲得坐標(biāo)的實(shí)現(xiàn)代碼
- JS onmousemove鼠標(biāo)移動坐標(biāo)接龍DIV效果實(shí)例
- javascript實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊頁面 移動DIV
- js拖動div 當(dāng)鼠標(biāo)移動時整個div也相應(yīng)的移動
- js實(shí)現(xiàn)鍵盤操作實(shí)現(xiàn)div的移動或改變的原理及代碼
- JavaScript利用鍵盤碼控制div移動
相關(guān)文章
JavaScript中執(zhí)行上下文和執(zhí)行棧
這篇文章主要介紹了JavaScript中執(zhí)行上下文和執(zhí)行棧,執(zhí)行上下文是評估和執(zhí)行JavaScript代碼的環(huán)境的抽象概念,更多相關(guān)介紹,感興趣的朋友可以參考一下2022-09-09簡述JavaScript提交表單的方式 (Using JavaScript Submit Form)
這篇文章主要介紹了簡述JavaScript提交表單的方式 (Using JavaScript Submit Form)的相關(guān)資料,需要的朋友可以參考下2016-03-03