鼠标离开之后为什么一直闪烁
<!doctype html>
<html>
<head>
<style>
*{margin:0;padding:0;}
#div1{width:200px;height: 200px;background: red;opacity:0.3;filter:alpha(opacity:30)};
</style>
<script type="text/javascript">
window.onload=function(){
var oDiv=document.getElementById("div1");
oDiv.onmouseover=function(){
startMove(1);
}
oDiv.onmouseout=function(){
startMove(0.3);
}
}
var int=null;
var alpha=0.3;
function startMove(iTarget){
var oDiv=document.getElementById("div1");
clearInterval(int);
int=setInterval(function(){
var speed=0;
if(alpha>iTarget)
{
speed=-0.1;
}
else
{
speed=0.1;
}
if(alpha==iTarget)
{
clearInterval(int);
}
else
{
alpha+=speed;
oDiv.style.opacity=alpha;
}
},30)
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>