代码如下。如果快速大幅度的划过鼠标,div便会消失。求解
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>下拉菜单</title>
<style type="text/css">
#div1{width: 200px; height: 200px; background: red; line-height: 100px; position: relative; left: 200px; top: 0px; filter: alpha(opacity:30); opacity: 0.3; top: 50px;}
body{ margin:0; padding:0;}
</style>
<script type="text/javascript">
window.onload=function(){
var oDiv=document.getElementById("div1");
oDiv.onmouseover=function(){
stareMove(100);
}
oDiv.onmouseout=function(){
stareMove(20);
}
var timer=null,
filter=30;
function stareMove(iTarget){
clearInterval(timer);
var oDiv=document.getElementById("div1");
var speed=0;
if (filter<iTarget) {
speed=10;
}
else{
speed=-10;
}
timer=setInterval(function(){
filter+=speed;
if (filter==iTarget) {
clearInterval(timer);
}
else{
oDiv.style.filter='alpha(opacity:filter)';
oDiv.style.opacity=filter/100;
}
},30)
}
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>