<!doctype html><html><head><meta charset="UTF-8"><title>Document</title><style type="text/css"> #box{width: 300px;height: 300px;background: red; opacity: 0.3; filter:alpha(opacity: 30)}</style><script type="text/javascript"> window.onload=function() { var Box=document.getElementById('box') Box.onmouseover=function() { startMove(100) } Box.onmouseout=function() { startMove(30) } } var timer=null; var alpha=30 function startMove(Target) { var Box=document.getElementById('box') clearInterval(timer) timer=setInterval(function() { var speed=0 if(alpha<Target) { spend=10 } else { spend=-10 } if(alpha==Target) { clearInterval(timer) } else { alpha+=speed Box.style.opacity=alpha/100; Box.style.filter='alpha(opacity:'+alpha+')' } },30) }</script></head><body><div id="box"></div></body></html>
添加回答
举报
0/150
提交
取消