weixin_慕勒4259824
2016-06-16 14:33
<!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>
if(speed>iTarget){
speed= -10;
}else{
speed= 10;
}
应该是if(opacity>iTarget)
JS动画效果
113925 学习 · 1443 问题
相似问题