谁能帮我看一下问题出在哪里?链式动画实现不了老师的效果,找了好久找不到
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>链式动画</title>
<style type="text/css">
*{margin:0;padding:0;}
ul{list-style:none;}
ul li{width: 200px;height: 100px;background: yellow;margin-bottom: 20px;border:4px solid #000;filter:alpha(opacity:30);opacity:0.3;}
</style>
<script>
window.onload=function(){
var li1=document.getElementById("li1");
li1.onmouseover=function(){
startMove(li1,'width',400,function(){
startMove(li1,'height',200,function(){
startMove(li1,'opacity',100);
});
});
}
li1.onmouseout=function(){
startMove(li1,'opacity',30,function(){
startMove(li1,'height',100,function(){
startMove(li1,'width',200);
});
});
}
}
function getStyle(obj,attr){
if(obj.currentStyle){
return obj.currentStyle[attr];//针对ie浏览器。
}else{
return getComputedStyle(obj,false)[attr];//针对firefox浏览器。
}
}
function startMove(obj,attr,target,fn){
clearInterval(obj.timer);
//取当前的值
obj.timer=setInterval(function(){
var cur=0;
if(attr=='opacity'){
cur=Math.round(parseFloat(getStyle(obj,attr))*100);
}else{
parseInt(getStyle(obj,attr));
}
//算速度
var speed=(target-cur)/8;
speed=speed>0?Math.ceil(speed):Math.floor(speed);
//检测停止
if(cur==target){
clearInterval(obj.timer);
if(fn){fn();}
}else{
if(attr=='opacity'){
obj.style.filter='alpha(opacity:'+(cur+speed)+')';//兼容IE浏览器
obj.style.opacity=(cur+speed)/100;
/*兼容firefox和chrome*/
}else{
obj.style[attr]=cur+speed+'px';
}
}
},30)
}
</script>
</head>
<body>
<ul>
<li id="li1"></li>
</ul>
</body>
</html>