为什么透明度动画按照老师的做没有效果,哪里出错了吗?求大神帮忙看看。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>2</title>
<style type="">
div{
width: 200px;
height: 200px;
margin: 10px;
float: left;
opacity: 0.3;
filter: alpha(opacity:30);
background-color: red;
}
</style>
<script type="text/javascript">
window.onload = function(){
var oDiv = document.getElementByTagName('div');
for (var i = 0; i <oDiv.length; i++) {
var oDiv[i].alpha = 30;
oDiv[i].onmouseover = function(){
startMove(this,100);
}
oDiv[i].onmouseout = function(){
startMove(this,30);
}
}
}
//var timer = null;
//var alpha = 30;
function startMove(obj,iTarget){
//var oDiv = document.getElementById('div1');
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var speed = 0;
if (obj.alpha>iTarget) {
speed = -10;
}
else{
speed = 10;
}
if (obj.alpha == iTarget) {
clearInterval(obj.timer);
}
else{
obj.alpha+=speed;
obj.style.filter = 'alpha(opacity'+obj.alpha+')';
obj.style.opacity = obj.alpha/100;
}
},30)
}
</script>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
<div id="div4"></div>
</body>
</html>