多物体运动动画js脚本

xiaoxiao2021-02-28  84

window.οnlοad=function(){ var aLi=document.getElementsByTagName('li'); for(var i=0;i<aLi.length;i++){ aLi[i].timer=null; aLi[i].οnmοuseοver=function(){ startMove(this,attr,400); } aLi[i].οnmοuseοut=function(){ startMove(this,attr,200); } } } // var timer=null;             var alpha=30;             function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; }else{ return getComputedStyle(obj,false)[attr]; } } //          startMove(obj,{attr1:iTarget1,attr2:iTarget2},fn) function startMove(obj,json,fn){ var flag=true; clearInterval(obj.timer); obj.timer=setInterval(function(){ for(var attr in json){ var icur=0; if(icur=='opacity'){ icur=Math.round(parseFloat(getStyle(obj,attr))*100); }else{ icur=parseInt(getStyle(obj,attr)); } //2.计算速度 var speed=(json[attr]-icur)/8; speed=speed>0?Math.floor(speed):Math.ceil(speed); //3.检测停止 if(icur!=json[attr]){ flag=false; } if(attr=='opacity'){ obj.style.filter='alpha(opacity:'+(icur+speed)+')'; obj.style.opacity=(icur+speed)/10; }else{ obj.style[attr]=icur+speed+'px'; } } if(flag){ clearInterval(obj.timer); if(fn){ fn(); } } },30) }
转载请注明原文地址: https://www.6miu.com/read-84558.html

最新回复(0)