问答详情
源自:5-1 JS链式动画

封装的函数都是一样的,主函数中将div换成了列表,为什么无法实现功能?

window.onload=function(){

var oli=document.getElementsByTagName("li");

for(i=0;i<oli[i].length;i++){

//oli[i].opacity=30;

oli[i].onmouseover=function(){

startmove(this,100,"opacity");

}

}

}

function startmove(obj,itarget,attr,fn){

clearInterval(obj.timer);

//var div1=document.getElementById("div1");

obj.timer=setInterval(function(){

var icur=0;

if(attr=="opacity"){

icur=Math.round(parseFloat(getstyle(obj,attr))*100);

}

else{

var 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[attr]=(icur+speed)/100;

obj.style['filter']='alpha(opacity:icur+speed)';

}

else{

obj.style[attr]=icur+speed+"px";

}

}

},30)

}

function getstyle(obj,attr){

if(obj.currentStyle){

return obj.currentStyle[attr];

}

else{

return getComputedStyle(obj,false)[attr];

}

}



提问者:我爱小小小橘子 2017-07-13 14:15

个回答

  • 慕粉3996208
    2017-07-13 16:27:13

     for (var i = 0; i < oli.length; i++)