ommouseover綁定兩個同名的函數為什么第一個函數就不執行了?代碼如下
<!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>這樣為什么就跳過了第一個函數直接執行第二個函數了?
2017-03-08
因為只有一個定時器。你調用兩次。。。
2018-09-06
...因為根據函數執行順序后面一個函數會覆蓋前面一個函數啊。。。。