兩種運(yùn)動(dòng)同事進(jìn)行怎么實(shí)現(xiàn)?
<!DOCTYPE?html> <html> <head> <meta?charset="utf-8"/> <title>多物體運(yùn)動(dòng)</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>
如果要實(shí)現(xiàn)offseWidth和opacity同時(shí)變化要怎樣實(shí)現(xiàn)?上述方法為什么不能實(shí)現(xiàn)?請(qǐng)大神指教
2015-10-19
是因?yàn)槟愣〞r(shí)器同名了,把第一個(gè)定時(shí)器的名稱(chēng)換成與第二個(gè)不一樣就好了。
2015-10-20
你好。接上面的問(wèn)題,如果把屬性封裝之后,width和opacity調(diào)用同一函數(shù)的話(huà),定時(shí)器不同名問(wèn)題該怎么解決?謝謝!
2015-10-20
Thanks!感謝!