和老师的代码几乎一样,为什么我的不能缩回来?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>多物体运动</title>
<style type="text/css">
li{height: 150px;width:150px;background: #ccc;margin:30px;list-style: none;}
</style>
<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() {
moveFun(this,400);
}
aLi[i].onmouseout=function() {
// body...
moveFun(this,400);
}
}
}
function moveFun(obj,iTarget){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(iTarget-obj.offsetWidth)/8;
speed=(speed>0)?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth==iTarget){
clearInterval(obj.timer);
}
else {
obj.style.width=obj.offsetWidth+speed+'px';
}
},30)
}
</script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>>