大家看看哪里出下问题了?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>多物体动画</title>
<style>
*{padding:0; margin:0; list-style: none;font-size: 36px;}
ul li{
/* width:150px; */
height:80px;
line-height: 80px;
background-color: #ff8040;
margin-bottom:20px;
border:4px #c0c0c0 solid;
text-align: center;
}
</style>
<script>
window.onload=function(){
var lis=document.getElementsByTagName("li");
for(var i=0;i<lis.length;i++)
{
lis[i].timer=null; //多物体运动所有参数不能共用,包括定时器,必须给各物体都加一个定时器
lis[i].onmouseover=function(){
move(this,300);
}
lis[i].onmouseout=function(){
move(this,150);
}
}
function move(obj,target){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var speed=(target-obj.offsetWidth)/10;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(obj.offsetWidth==target)
clearInterval(obj.timer);
else
obj.style.width=parseInt(obj.style.width)+speed+'px';
},50);
}
}
</script>
</head>
<body>
<ul >
<li width="150px">1</li>
<li width="150px">2</li>
<li width="150px">3</li>
</ul>
</body>
</html>