两种运动同事进行怎么实现?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>多物体运动</title> <style type="text/css"> *{ margin: 0; padding: 0; } ul,li{ list-style: none; } ul li{ width: 200px; height: 100px; background: red; margin-bottom: 20px; filter:alpha(opacity:30); opacity: 0.3; } </style> <script> window.onload = function(){ var aLi = document.getElementsByTagName('li'); for(var i = 0;i < aLi.length;i++){ aLi[i].timer = null; aLi[i].alpha = 30; aLi[i].onmouseover = function(){ startMove(this,400); changeColor(this,100); } aLi[i].onmouseout = function(){ startMove(this,200); changeColor(this,30); } } } function startMove(obj,iTarget){ clearInterval(obj.timer); obj.timer = setInterval(function(){ var speed = (iTarget-obj.offsetWidth)/10; speed = speed>0?Math.ceil(speed):Math.floor(speed); if(iTarget == obj.offsetWidth){ clearInterval(obj.timer); } else{ obj.style.width = obj.offsetWidth+speed+'px'; } },30) } function changeColor(obj,iTarget){ clearInterval(obj.timer); obj.timer = setInterval(function(){ var speed = (iTarget - obj.alpha)/10; speed = speed>0?Math.ceil(speed):Math.floor(speed); if (iTarget == obj.alpha) { clearInterval(obj.timer); } else{ obj.alpha+=speed; obj.style.filter = 'alpha(opacity:'+obj.alpha+')'; obj.style.opacity = obj.alpha/100; } },30) } </script> </head> <body> <ul> <li></li> <li></li> <li></li> </ul> </body> </html>
如果要实现offseWidth和opacity同时变化要怎样实现?上述方法为什么不能实现?请大神指教