下面的代码为什么不能实现鼠标移入移出div1的width在200px到600px之间变化?
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>运动框架</title>
<style type="text/css">
*{ margin: 0; padding: 0;}
#div1{ width: 200px; height: 100px; background-color: #ff0000;}
</style>
<script type="text/javascript">
window.onload = function(){
oDiv = document.getElementById('div1');
oDiv.onmouseover = function(){
startMove(600);
}
oDiv.onmouseout = function(){
startMove(200);
}
}
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}else{
return getComputedStyle(obj,false)[attr];
}
}
var timer = null;
function startMove(iTarget){
clearInterval(timer);
var oDiv = document.getElementById('div1');
var div_width = parseInt(getStyle(oDiv,'width'));
timer = setInterval(function(){
var speed = 0;
if(div_width > iTarget){
speed = -10;
}else if(div_width <iTarget){
speed = 10;
}
if(div_width == iTarget){
clearInterval(timer);
}else{
oDiv.style.width = div_width + speed + 'px';
}
},30)
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>