为什么透明度动画按照老师的做没有效果,哪里出错了吗?求大神帮忙看看。

来源:4-1 JS多物体动画

AINIforever

2016-11-13 13:31

<!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>


写回答 关注

2回答

  • 游盼
    2016-11-13 15:01:41
    已采纳

    兄弟你这里错了:

    http://img.mukewang.com/58280fd00001007604550153.jpg


    AINIfo...

    谢谢了

    2016-11-13 19:06:08

    共 3 条回复 >

  • AINIforever
    2016-11-13 18:39:18

    重复定义?

JS动画效果

通过本课程JS动画的学习,从简单动画开始,逐步深入各种动画框架封装

113925 学习 · 1443 问题

查看课程

相似问题