问答详情
源自:2-2 JS透明度动画

找不到错误啊,感觉一样啊 ,透明度没反应

<!DOCTYPE html>

<html>

<head>

<title>透明度</title>

<meta charset="utf-8">

<style type="text/css">

*{margin: 0;padding: 0;}

#box{

width: 200px;

height: 200px;

background: red;

opacity: 0.3;

cursor: pointer;

}

</style>

<script type="text/javascript">

window.onload=function(){

var box=document.getElementById('box');

box.ommouseover=function(){

setMove(100);

}

box.onmouseout=function(){

setMove(30);

}

}


//setMove

var timer=null,

alpha=30;

function setMove(target){

var box=document.getElementById('box');

clearInterval(timer);

timer=setInterval(function(){

var speed=alpha>target?-10:10;

if(alpha==target){

clearInterval(timer);

}

else{

alpha=alpha+speed;

box.style.opacity=alpha/100;

}

},30)

}


</script>

</head>

<body>

<div id="box"></div>

</body>

</html>


提问者:慕粉1235143442 2017-04-16 19:14

个回答

  • 慕粉1235143442
    2017-04-16 19:25:11

    发现了,onmouseover的n写成了m,哭