clearIntelval(timer)报错?第一次使用clearIntelval(timer)报错
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>运动</title>
<style type="text/css">
*{margin: 0;padding: 0;}
#box{width: 200px;height: 200px;background-color: red;position: relative;left: -200px;top: 0;}
#box span{width: 20px;height: 50px;position: absolute;top: 50px;left: 200px;background-color: blue;}
</style>
<script type="text/javascript">
window.onload=function(){
var obox = document.getElementById('box');
obox.onmouseover = function () {
startmove();
}
/* obox.onmouseout = function(){
backmove();
}
*/ }
var timer = null;
function startmove() {
clearIntelval(timer);
var obox = document.getElementById('box');
timer = setInterval(function () {
if (obox.offsetLeft==0) {
clearInterval(timer);
}else{
obox.style.left = obox.offsetLeft + 1 +"px";
}
},30)
}
/* function backmove(){
clearIntelval(timer);
var obox = document.getElementById('box');
timer = setInterval(function(){
if (obox.offsetLeft == -200) {
clearInterval(timer);
}else{
obox.style.left = obox.offsetLeft - 10 +"px";
}
},30)
}
*/
</script>
</head>
<body>
<div id="box"><span>分享</span></div>
</body>
</html>