明明和老师的代码是一样的,为什么我的在多次点击的时候还是跑的很快,感觉前面那个清除没有作用
<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js运动</title>
<style>
*{margin:0px;padding:0px;}
#div1{height:200px;
width:200px;
background:red;
position:relative;
left:-200px;}
#share{width:50px;
height50px;
background:blue;
position:absolute;
top:100px;
left:200px;
}
</style>
<script>
window.onload=function(){
var odiv=document.getElementById("div1");
odiv.onmouseover=function(){
startMove();
}
}
var timer=null;
function startMove(){
clearInterval(timer);
var odiv=document.getElementById("div1");
setInterval(function(){
if(odiv.offsetLeft==0){
clearInterval(timer);
}
else{
odiv.style.left=odiv.offsetLeft+1+"px";
}
},30)
}
</script>
</head>
<body>
<div id="div1">
<span id="share">分享</span>
</div>
</body>
</html>