请教我的这段代码为什么在所有运动到达目标之前移开鼠标会无法正常变回原样?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
#box {width:200px;height:200px;opacity:0.5;border:#333 1px solid;background:#3F9;opacity:0.5;filter:alpha(opacity:50);}
</style>
<script type="text/javascript">
window.onload=function(){
var box=document.getElementById("box");
box.onmouseover=function(){
move(box,300,'width');
}
box.onmouseout=function(){
move(box,200,'width')
}
function getStyle (obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}
else{
return getComputedStyle(obj,false)[attr];
}
}
function move(obj,target,attr,fn){
obj.timer=null;
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var cur=0;
if (attr=='opacity')
{
var cur=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else{
var cur=parseInt(getStyle(obj,attr));
}
var speed=(target-cur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if (cur==target)
{
clearInterval(obj.timer);
if(fn){
fn();
}
}
else{
if (attr=='opacity')
{
obj.style.filter='alhpa(opacity:'+(cur+speed)+')';
obj.style.opacity=(cur+speed)/100;
}
else{
obj.style[attr]=cur+speed+'px';
}
}
},30)
}
}
</script>
</head>
<body>
<div id=box></div>
</body>
</html>