ommouseover綁定兩個同名的函數(shù)為什么第一個函數(shù)就不執(zhí)行了?代碼如下
<!DOCTYPE?html> <html> <head> <meta?charset="utf-8"> <title></title> <style?type="text/css"> ul,li{ list-style:?none; } ul?li{ width:?200px; height:?100px; background:?red; margin-bottom:?20px; border:?4px?solid?#000; font-size:?8px; } </style> <script?type="text/javascript"> window.onload=function(){ var?aLi=document.getElementsByTagName("li"); for?(var?i=?0;?i<aLi.length;i++)?{ aLi[i].timer=null; aLi[i].onmouseover=function(){ startMove(this,400,'width'); startMove(this,200,'height'); } aLi[i].onmouseout=function(){ startMove(this,200,'width'); startMove(this,100,'height'); } } } function?startMove(obj,iTarget,attr){ clearInterval(obj.timer); obj.timer=setInterval(function(){ var?speed=(iTarget-parseInt(getStyle(obj,attr)))/10; speed=speed>0?Math.ceil(speed):Math.floor(speed); if(parseInt(getStyle(obj,attr))==iTarget){clearInterval(obj.timer);} else{obj.style[attr]=parseInt(getStyle(obj,attr))+speed+'px'; }? },20); } function?getStyle(obj,attr){ if(obj.currentStyle){ return?obj.currentStyle[attr]; } else{ return?getComputedStyle(obj,false)[attr]; } } </script> </head>?? <body> <ul> <li></li> <li></li> <li></li> </ul> </body> </html>
這樣為什么就跳過了第一個函數(shù)直接執(zhí)行第二個函數(shù)了?
2017-03-08
因為只有一個定時器。你調用兩次。。。
2018-09-06
...因為根據函數(shù)執(zhí)行順序后面一個函數(shù)會覆蓋前面一個函數(shù)啊。。。。