求大神解答。。。实在不知道错哪里了。。哭了
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
*{margin:0;padding: 0}
ul li{width: 200px;height: 100px;background-color: red;margin-bottom: 10px;border: 4px solid #000}
ul li{list-style: none;}
</style>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</body>
<script type="text/javascript">
window.onload=function(){
var aLi=document.getElementsByTagName('li');
for(var i=0;i<aLi.length;i++){
aLi[i].timer=null;
aLi[i].onmouseover=function(){
moveto(this,400);//让宽到300
}
aLi[i].onmouseout=function(){
moveto(this,200);
}
}
}
function getStyle(obj,style){
if(obj.currentStyle){
return obj.currentStyle[style];
}
else{
return getComputedStyle(obj,false)[style];
}
}
function moveto(obj,itarget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var icur=parseInt(getStyle(obj,'width'));
var speed=(itarget-icur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(icur==itarget){
clearInterval(obj.timer);
}
else{
obj.style.width=icur+speed+'px'
//console.log(icur+' ,'+speed+' ,'+obj.style.width);
}
},30)
}
</script>
</html>