码迷,mamicode.com
首页 > 编程语言 > 详细

javascript背景淡入淡出

时间:2014-06-15 11:27:44      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   java   http   tar   

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style type="text/css">
        #div1
        {
            width: 200px;
            height: 200px;
            background-color: green;
            filter: alpha(opacity=20);
            opacity: 0.2;
        }
    </style>
    <script type="text/javascript">
        var alpha = 30;
        var timer = null;
        window.onload = function () {
            var oDiv = document.getElementById("div1");
            oDiv.onmouseover = function () {
                Move(100);
            }
            oDiv.onmouseout = function () {
                Move(30);
            }
        }
        function Move(iTarget) {
            var speed = 0;
            clearInterval(timer);

            var oDiv = document.getElementById("div1");

            timer = setInterval(function () {
                if (alpha < iTarget) {
                    speed = -3;
                } else if (alpha == iTarget) {
                    speed = 3;
                }
                //开始变色
                if (alpha == iTarget) {
                    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>

  

javascript背景淡入淡出,布布扣,bubuko.com

javascript背景淡入淡出

标签:style   class   blog   java   http   tar   

原文地址:http://www.cnblogs.com/alphafly/p/3789209.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!