鼠标移出的效果没有
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#box{
width: 200px;
height: 200px;
background: red;
opacity: 0.3;
filter:alpha(opacity:30);
}
</style>
</head>
<body>
<div id="box"></div>
<script>
window.onload=function(){
var box = document.getElementById("box"),
timer = null,
opacity = 30;
box.onmouseover = function(){
boxChang(100);
}
box.onmouseout = function(){
boxChang(30);
}
function boxChang(iTarget){
clearInterval(timer);
timer = setInterval(function(){
var speed = 0;
if(speed>iTarget){
speed= -10;
}else{
speed= 10;
}
if(iTarget==opacity){
clearInterval(timer);
}else{
opacity += speed;
box.style.filter = 'alpha(opacity'+opacity+')';
box.style.opacity = opacity/100;
}
},30)
}
}
</script>
</body>
</html>