找不到错误啊,感觉一样啊 ,透明度没反应
<!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>