求大神帮我看下这代码,鼠标离开的时候,div不会回去呀?是什么问题?
<!DOCTYPE html>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Js动画</title>
<style type="text/css">
<style>
*{margin:0;padding:0;}
#div1{
width:200px;
height:200px;
background:red;
position:relative;
left:-200px;
top:0;
}
#div1 span{
height: 50px;
position: absolute;
background:blue;
width: 20px;
left: 200px;
top: 75px;
}
</style>
</head>
<script type="text/javascript">
window.onload=function(){
var oDiv=document.getElementById('div1');
oDiv.onmouseover=function(){
startMove(0);
}
oDiv.onmouseout=function(){
startMove(-200);
}
}
var timer=null;
function startMove(iTarget){
clearInterval(timer);
var oDiv=document.getElementById('div1');
timer=setInterval(function(){
var speed= 0;
if (oDiv.offsetLeft>iTarget) {
speed==-10;
}else{
speed==10;
}
if(oDiv.offsetLeft==iTarget){
clearInterval(timer);
}
else{
oDiv.style.left=oDiv.offsetLeft+speed+'px';
}
},30)
}
</script>
<body>
<div id="div1">
<span id="share">分享</span>
</div>
</html>