javascript实现点击按钮让DIV层弹性移动的方法
本文实例讲述了javascript实现点击按钮让DIV层弹性移动的方法。分享给大家供大家参考。具体实现方法如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>点击按钮让DIV层弹性移动特效</title>
<styletype="text/css">
#div1{background:#FFCC66;border:#FF66001pxsolid;height:100px;width:100px;position:relative;left:0px;}
</style>
<scripttype="text/javascript">
vart=null;
functionstartMove()
{
if(t)
{
clearInterval(t);
}
t=setInterval(move,30);
}
varstep=0;
functionmove()
{
varodiv=document.getElementById("div1");
step+=(100-odiv.offsetLeft)/50;
step=step*0.98
odiv.style.left=odiv.offsetLeft+step;
}
</script>
</head>
<body>
<divid="div1">
</div>
<inputtype="button"value="移动"onclick="startMove()"/>
</body>
</html>
希望本文所述对大家的javascript程序设计有所帮助。
热门推荐
10 喜得孙子祝福语简短唯美
11 婚礼祝福语简短朴实大众
12 员工周年祝福语大全简短
13 家长回复节日祝福语简短
14 简短生日祝福语老同学
15 夜雨祝福语简短10字
16 蛋糕祝福语简短闺蜜
17 部门过年祝福语简短独特
18 简短精炼的结婚祝福语