为什么没有运动?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type='text/css'>
#div1{
height:100px;
background: red;
width:200px;
color:black;
font-size: 12px;
margin-bottom: 20px;
border: 1px solid black;
}
</style>
<script type="text/javascript">
window.onload=function(){
var oDiv = Document.getElementById('div1');
oDiv.onmouseover=function(){
startMove(oDiv,'width',400,function(){
startMove(oDiv,'height',200);
});
}
}
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];//ie浏览器内核
}else{
return getComputedStyle(obj,false)[attr];//火狐浏览器内核
}
}
var timer=null;
function startMove(obj,attr,iTarget,fn){
clearInterval(obj.timer);//1.2+++
obj.timer=setInterval(function(){//1.2+++
var icur=0;
icur=parseInt(getStyle(obj,attr));
var speed=(iTarget-icur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(icur==iTarget){
if(fn){
fn();
}
clearInterval(obj.timer);//1.2+++
}else{
obj.style[attr]=icur+speed+'px';
}
},30);
}
</script>
</head>
<body>
<ul>
<div id='div1'>哈哈</div>
</body>
</html>