求救,速度动画我用两个参数做是可以运行的,这个透明度,我鼠标移入移出,透明度没变啊,求大佬们看下代码
<!DOCTYPE html>
<html>
<head>
<title>透明度动画</title>
<style type="text/css">
body,div{margin: 0;padding: 0;}
#div1
{
width: 200px;
height: 200px;
background: red;
opacity: 0.3;
}
</style>
<script type="text/javascript">
window.onload = function(){
var oDiv = document.getElementById('div1')
oDiv.onmouseover = function(){
startMove(10,100);
oDiv.onmouseout = function(){
startMove(-10,30);
}
}
var timer = null;
var alpha = 30;
function startMove(speed,iTarget){
clearInterval(timer);
var oDiv = document.getElementById('div1')
timer = setInterval(function(){
if (alpha==iTarget) {
clearInterval(timer);
}
else {
alpha+=speed;
oDiv.style.opacity = alpha/100;
}
},30)
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>