timer前面加上了var,取消定時器就失效了,這是為什么? 求大神解答,

<script?type="text/javascript">
window.onload=function(){
var?box1=?document.getElementById("box1");
box1.onmouseover=function(){
mvfn1();
}
};
var?timer?=?null?;
function?mvfn1(){
clearInterval(timer);
var?box1=?document.getElementById("box1");
var?timer=setInterval(function(){
if?(box1.offsetLeft>=0)?{
clearInterval(timer);
}?else{
box1.style.left=box1.offsetLeft+1+"px";
}
},30);
};
</script>
2016-08-10
這樣你就把全局變量變成局部變量了