<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>多物体缓冲运动</title>
</head>
<style>
*{margin:0px;padding:0px;}
#move li{width:200px;height:100px;display:block;margin-bottom:20px;background:yellow;list-style:none;}
</style>
<script>
window.onload=function(){
var oul=document.getElementById(‘move‘);
var ali=oul.getElementsByTagName(‘li‘);
var timer=null
for(var i=0;i<ali.length;i++){
ali[i].onmouseover=function(){
startMove(this,400);
}
ali[i].onmouseout=function(){
startMove(this,200);
}
}
function startMove(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>
<body>
<ul id="move">
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>多物体缓冲运动</title>
</head>
<style>
*{margin:0px;padding:0px;}
#move li{width:200px;height:100px;display:block;margin-bottom:20px;background:yellow;list-style:none;}
</style>
<script>
window.onload=function(){
var oul=document.getElementById(‘move‘);
var ali=oul.getElementsByTagName(‘li‘);
var timer=null
for(var i=0;i<ali.length;i++){
ali[i].onmouseover=function(){
startMove(this,400);
}
ali[i].onmouseout=function(){
startMove(this,200);
}
}
function startMove(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>
<body>
<ul id="move">
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>