为什么不显示透明呢 ?麻烦帮我看下!谢谢

来源:2-2 JS透明度动画

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>


写回答 关注

6回答

JS动画效果

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

113939 学习 · 1443 问题

查看课程

相似问题