<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title><style>#box1{ width:200px; height:200px; background-color:red; opacity:0.3;}</style></head><body><div id="box1"></div><script>window.onload=function(){ var mydiv=document.getElementById("box1"); mydiv.onmouseover=function(){ startMove(0.1,1); }mydiv.onmouseout=function(){ startMove(-0.1,0.3); } }var myopacity=0.3;function startMove(speed,mytarget){ clearInterval(i); var mydiv=document.getElementById("box1"); var i=null; i=setInterval(function(){ if(myopacity==mytarget){ clearInterval(i); } else { mydiv.style.opacity=myopacity+speed; } },30) } <!--end of startMove--></script></body></html>
添加回答
举报
0/150
提交
取消