为什么鼠标移入一次才触发一次而不是链式的?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>relative样式</title>
<style type="text/css">
*{margin:0;padding:0}
ul,li{list-style:none}
ul li{width:200px;
height:100px;
background:yellow;
margin-bottom:20px;
border:2px solid #000;
filter:alpha(opacity:30);
opacity: 0.3;
}
</style>
<script type="text/javascript">
window.onload=function(){
var Li=document.getElementById("li1");
Li.onmouseover=function(){
startMove(Li,{width:400},function(){
startMove(Li,{height:200},function(){
startMove(Li,{opacity:100});
});
});
}
}
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}
else{
return getComputedStyle(obj,false)[attr];
}
}
var alpha=30;
function startMove(obj,json,fn){
var flag=true;
clearInterval(obj.timer);
obj.timer=setInterval(function(){
for(var attr in json){
var icur=0;
if(attr=='opacity'){
icur=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else{
icur=parseInt(getStyle(obj,attr));
}
var a=(json[attr]-icur)/8;
a=a>0?Math.ceil(a):Math.floor(a);
if(icur!==json[attr]){
flag=false;
}
if(attr=='opacity'){
obj.style.filter='alpha(opacity:'+(icur+a)+')';
obj.style.opacity=(icur+a)/100;
}
else{
obj.style[attr]=icur+a+'px';
}
if(flag){
clearInterval(obj.timer);
if(fn){
fn();
}
}
}
},30)
}
</script>
</head>
<body>
<ul>
<li id="li1"></li>
</ul>
</body>
</html>