JS多物体透明度运动

来源:互联网 发布:java传递参数基本类型 编辑:程序博客网 时间:2024/05/22 02:05

多物体不能有公用属性

window.onload=function(){var aDiv=document.getElementsByTagName('div');for(var i=0;i<aDiv.length;i++){aDiv[i].alpha=30;aDiv[i].onmouseover=function(){startMove(this,100);};aDiv[i].onmouseout=function(){startMove(this,30);};}}function startMove(obj,iTarget){clearInterval(obj.timer);obj.timer=setInterval(function(){var speed=(iTarget-obj.alpha)/6;speed=speed>0?Math.ceil(speed):Math.floor(speed);if(obj.alpha==iTarget){clearInterval(obj.timer);}else{obj.alpha+=speed;obj.style.filter='alpha(opacity:'+obj.alpha+')';obj.style.opacity=obj.alpha/100;}},30);}


原创粉丝点击