Alice611
2016-01-11 19:49
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
body,div{
margin:0;
padding:0;
}
#div1{
width:200px;
height:200px;
background-color:red;
filter:alpha(opacity:30);//透明度30
opacity:0.3;
}
</style>
<script type="text/jscript">
window.onload=function(){
var oDiv=document.getElementById("div1");
//鼠标移入透明度100
oDiv.onmouseover=function(){
starMove(100);
}
//鼠标移出透明度30
oDiv.onmouseout=function(){
starMove(30);
}
}
var timer=null;
var alpha=30;
function starMove(iTaget){
var oDiv=document.getElementById("div1");
clearInterval(timer);
timer=setInterval(function(){
var speed=0;//变量初始值为0;
if(alpha>=iTaget){
speed=-10;
}
else{
speed=10;
}
if(alpha==iTaget){
clearInterval(timer);
}
else{
alpha+=speed;
odiv.style.filter="alpha(opacity:‘+alpha+')";
oDiv.style.opacity=alpha/100;
}
},30)
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
<script type="text/javascript"> <!--这里的type值,要写就要写正确,要么就不写---->
oDiv.style.filter = "alpha(opacity:‘+alpha+')"; //这里的oDiv 写成了 odiv
oDiv.style.filter = "alpha(opacity:" + alpha + ")";
oDiv.style.filter="alpha(opacity:'+alpha+')"; odiv改成oDiv,opacity:'+alpha+'前面的那个引号号要切换英文输入引号
odiv.style.filter="alpha(opacity:‘+alpha+')";应该是oDiv吧大小写
<script type="text/jscript">应该是<script type="text/javascript">
JS动画效果
113925 学习 · 1443 问题
相似问题