不能透明 帮看看吧

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

一杯青梅

2016-03-28 00:05

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<title>Examples</title>

<meta name="description" content="">

<meta name="keywords" content="">

<!-- <link href="./css/005.css" rel="stylesheet"> -->

<style type="text/css">

*{

margin: 0;

padding: 0;

}

#div1{

width: 200px;

height: 200px;

background: red;

filter: alpha(opacity:30);

/*透明度为0.3*/

opacity: 0.3;

}

</style>

<script>

/**

 * 

 * @authors Your Name (you@example.org)

 * @date    2016-03-27 22:46:46

 * @version $Id$

 */

// 打开窗口后直接加载的函数

window.onload=function () {

var oDiv=document.getElementByid('div1');

oDiv.onmouseover=function(){

startMove(100);

}

oDiv.onmouseout=function(){

startMove(30);

}

}

var alpha=30;

var timer=null;

function startMove(xTarget) {

clearInterval(timer);

var oDiv=document.getElementByid('div1');

timer=setInterval(function(){

var speed=0;

if (alpha>xTarget) {

speed=-10;

} else {

speed=10;

}

if (alpha==xTarget) {

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>


写回答 关注

2回答

  • 丁吉瑞斯
    2016-03-28 09:46:54
    已采纳

    同学,把你的代码中document.getElementById中的id(小写I)全部换成Id(大写I)就ok了哦

    丁吉瑞斯 回复一杯青梅

    不客气哦

    2016-03-29 09:07:01

    共 2 条回复 >

  • 和光
    2016-03-28 09:50:11

    ”document.getElementByid“写错了,是Id是不是id

JS动画效果

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

113918 学习 · 1502 问题

查看课程

相似问题