<!doctype html><html><head><meta charset="UTF-8" /><title>Document</title><style type="text/css">*{margin: 0;padding: 0;}div{width: 100px;height: 100px;background: red;float: left;margin-right: 20px;position: relative;left:500px;top: 100px;filter: alpha(opacity = 30);opacity: 0.3;}</style><script type="text/javascript">window.onload=function(){var aDiv = document.getElementsByTagName('div');for(var i = 0;i<aDiv.length;i++){aDiv[i].timer = null;aDiv[i].Valpha = 30;aDiv[i].onmouseover = function(){startMove(this,30);}aDiv[i].onmouseout = function(){startMove(this,100);}}function startMove(obj,target){clearInterval(obj.timer);obj.timer = setInterval(function(){var speed = (target - obj.Valpha)/6;speed = speed > 0?Math.ceil(speed) : Math.floor(speed);if(obj.Valpha == target){clearInterval(obj.timer);}else{obj.Valpha += speed;obj.style.filter = 'alpha(opacity:' + obj.Valpha +')';obj.style.opacity = obj.Valpha;}},30)}}</script></head><body> <div></div> <div></div> <div></div></body></html>
添加回答
举报
0/150
提交
取消