<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>多物体运动</title> <style> *{margin: 0;padding: 0} .li1{width:100px;height:100px; margin-bottom: 50px;background-color: teal;} .li2{width:100px;height:100px; margin-bottom: 50px;background-color: teal;} .li3{width:100px;height:100px; margin-bottom: 50px;background-color: teal;} </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=go(this,400); lis[i].onmouseout=go(this,100); } } function go(obj,target) { clearInterval(obj.timer); obj.timer=setInterval(function(){ var speed=(target-obj.offsetWidth)/30; speed=speed<0?Math.floor(speed):Math.ceil(speed); if(obj.offsetWidth==target){ clearInterval(obj.timer); } else{ obj.style.width=obj.offsetWidth+speed+'px'; } },30); } </script> </head> <body> <li></li> <li></li> <li></li> </body> </html>
风筝_0010
相关分类