各位大神,看一下我的为什么不能停止。
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
#div1{
width:200px;
height:200px;
background-color:red;
position:relative;
left:-200px;
top:0px;
}
#share{
width:20px;
height:50px;
background-color:blue;
position:absolute;
left:200px;
top:50px;}
</style>
<script >
window.onload=function(){
var oDiv=document.getElementById("div1");
oDiv.onmouseover=function(){
startMove();
}
}
var timer=null;
function startMove(){
var oDiv=document.getElementById("div1");
timer=setInterval(function(){
if(oDiv.offsetLeft == 0)
{
clearInterval(timer);
}
else{
oDiv.style.left=oDiv.offsetLeft+10+'px';
}
}
,30);
}
</script>
</head>
<body>
<div id="div1"><span id="share">点击</span></div>
</body>
</html>