我感覺(jué)沒(méi)錯(cuò)啊,誰(shuí)看看有沒(méi)有錯(cuò),謝了!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無(wú)標(biāo)題文檔</title>
<style type="text/css">
li{
list-style:none;
width:200px;
height:100px;
background:yellow;
margin-bottom:10px;
}
</style>
<script type="text/javascript">
var oLi=document.getElementsByTagName("li");
for(var i;i<oLi.length;i++){
oLi[i].timer=0;
oLi[i].onmouseover= function(){
startMove(this,{width:400,height:200},fn());
}
oLi[i].onmouseout=function(){
startMove(this,{width:200,height:100},fn());
}
}
function startMove(oLi,attr,fn){
//var flag=true;//原有的
clearInterval(oLi.timer);
oLi.timer=setInterval(function(){
var flag=true;//添加的
for(var i in attr)
{
//1.取當(dāng)前值
var iCur=0;
if(i=='opacity')
{iCur=Math.round(parseFloat(getStyle(oLi,i))*100);}
else {iCur=parseInt(getStyle(oLi,i));}
//2.算速度
var speed=(attr[i]-iCur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
//檢測(cè)停止
if(iCur!=attr[i])
{
flag=false;
if(i!='opacity')
oLi.style['i']=iCur+speed+'px';
else {
oLi.style['i']=(iCur+speed)/100;
oLi.style['i']='alpha(opacity:'+(iCur+speed)+')';
}
}
/*if(flag) //原有的
{
clearInterval(oLi.timer);
if(fn){fn();}
}*/
}
if(flag)
{
clearInterval(oLi.timer);
if(fn){fn();}
}
},30);
}
</script>
</head>
<body>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</body>
</html>