为什么我的代码中的move()函数和remove()函数中的用来清除上一个定时器的clearInterval(timer)不管用呢?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0
}
#div{
width: 300px;
height: 200px;
background: red;
position: relative;
left: -300px;
}
span{
display: block;
width: 20px;
height: 40px;
background: blue;
position: relative;
left: 300px;
top: 90px;
writing-mode:tb-rl;
text-align: center;
}
</style>
<script>
window.onload=function(){
var div=document.getElementById('div'),
timer=null;
div.onmouseover=function(){
move();
}
div.onmouseout=function(){
remove();
}
function move(){
clearInterval(timer);
temer=setInterval(function(){
if(div.offsetLeft==0){
clearInterval(timer);
}else{
div.style.left=div.offsetLeft+1+'px';
}
},10)
}
function remove(){
clearInterval(timer);
temer=setInterval(function(){
if(div.offsetLeft==-300){
clearInterval(timer);
}else{
div.style.left=div.offsetLeft-1+'px';
}
},10)
}
}
</script>
</head>
<body>
<div id="div"><span>分享</span></div>
</body>
</html>