<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
#div1{height:300px;width:300px;background-color:red;position:absolute;left:0px;}
</style>
</head>
<body>
<input id="btn" type="button"/ value="点击移动">
<div id="div1"></div>
</body>
<script>
var oBtn=document.getElementById("btn");
var oDiv1=document.getElementById("div1");
oBtn.onclick=function(){
toright(600,function(){alert("a")})
}
function toright(win,fn){
var timer=null;
timer=setInterval(function(){
var iSpeed=(win-oDiv1.offsetLeft)/20;
if (oDiv1.offsetLeft>=win)
{
clearInterval(timer);
if(fn){fn();};
}
else
{
oDiv1.style.left=oDiv1.offsetLeft+iSpeed+"px";
};
},20);
}
</script>
</html>
添加回答
举报
0/150
提交
取消