多物体,不同目标值
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>多图动画</title> <style type="text/css"> *{margin: 0; padding: 0;} ul,li{list-style: none;} li{width: 100px; height: 100px; background-color: red; margin-bottom: 50px;} </style> <script type="text/javascript"> window.onload=function () { var li=document.getElementsByTagName('li'); var itarget=200; for (var i = 0; i < li.length; i++) { li[i].timer=null; li[i].onmouseover=function(){ startmove(this,itarget); } li[i].onmouseout=function(){ startmove(this,100); } itarget+=100; } } function startmove (obj,itarget) { clearInterval(obj.timer); obj.timer=setInterval(function(){ obj.speed=Math.floor((itarget-obj.offsetWidth)/10); if (itarget==obj.offsetWidth) { clearInterval(obj.timer); } else{ obj.style.width=obj.offsetWidth+obj.speed+'px'; } },30) } </script> </head> <body> <ul> <li></li> <li></li> <li></li> </ul> </body> </html>
为什么三个物体的目标值都是400呢,怎么可以设置目标值为200,300,400,三个都不一样