链式动画动不了。。。求大神指点5555555
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <style> *{ padding: 0; margin:0; } ul,li{ list-style: none; } ul li{ width:200px; height: 100px; background: yellow; margin-bottom: 20px; border:4px solid #000; font-size: 10px; color:red; filter: :alpha(opacity:30); opacity: 0.3; } </style> <script src='move.js'></script> <script> window.onload=function(){ var li=document.getElementById('li1'); li.onmouseover=function(){ startMove(li,400,'height',function(){ startMove(li,200,'width'); }); } } </script> </head> <body> <ul> <li id="li1"></li> </ul> </body> </html>
//------------move.js--------------------------
function startMove(obj,iTarget,attr,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(obj.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';
}
}
})
}
function getStyle(obj,attr)
{
if(obj.currentStyle){
return obj.currentStyle[attr];
}else
{
return getComputedStyle(obj,false)[attr];
}
}