求助:为啥只能执行单个运动,不能执行链式运动
<!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=gb2312" />
<title>无标题文档</title>
<style type="text/css">
ul,li{
list-style:none;
}
ul li{
width:200px;
height:100px;
background:#FF0000;
margin-bottom:20px;
filter:alpha(opacity:30);
opacity:0.3;
border:4px solid #000;
}
</style>
<script src="soprt.js"></script>
<script>
window.onload=function(){
var ali=document.getElementsByTagName("li");
for(i=0;i<ali.length;i++){
ali[i].timer=null;
ali[i].onmouseover=function(){
startMove(this,"width",400,function(){
startMove(this,"height",400);
});
}
}
}
</script>
</head>
<body>
<ul>
<li id="li1"></li>
<li></li>
<li></li>
</ul>
</body>
</html>
// JavaScript Document//获取样式的封装函数
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];
}
else{
return getComputedStyle(obj,false)[attr];
}
}
//运动函数
function startMove(obj,attr,iTarget,fn){
clearInterval(obj.timer);
obj.timer=setInterval(function(){
var icur=0;
if(attr=="opacity"){
icur=Math.round(parseFloat(getStyle(obj,attr))*100);
}
else{
icur=parseInt(getStyle(obj,attr));
}
var speed=(iTarget-icur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
//检测停止
if(icur==iTarget){
clearInterval(timer);
if(fn){
fn();
}
}
else{
//判断是否是透明度
if(attr=="opacity"){
obj.style.filter="alpha(opacity:"+(icur+speed)+")";
obj.style.opacity=(icur+speed)/100;
}
else{
obj.style[attr]=icur+speed+"px";
}
}
},30)
}