码迷,mamicode.com
首页 > Web开发 > 详细

js笔记----(运动)淡入淡出

时间:2014-10-28 19:26:02      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   java   sp   div   

<!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>
        #img1 { height:300px; width:300px; margin:30px auto; filter:alpha(opacity=30); opacity:0.3; }
    </style>
    <script type="text/javascript">
        window.onload = function () {
            var oImg = document.getElementById(img1);
            oImg.onmouseover = function () {
                StarMove(100);
            }
            oImg.onmouseout = function () {
                StarMove(30);
            }
        }
        var timer = null;
        var alpha = 30;
        function StarMove(iTarget)
        {
            var oImg = document.getElementById(img1);
            var iSpeed = 0;
            if (alpha < iTarget) {
                iSpeed = 5;
            }
            else {
                iSpeed = -5;
            }
            clearInterval(timer);
            timer = setInterval(function () {
                alpha += iSpeed;
                if (alpha == iTarget) {
                    clearInterval(timer);
                }
                else {
                    oImg.style.filter = "alpha(opacity=" + alpha + ")";
                    oImg.style.opacity = alpha / 100;
                }
            }, 30);
        }
    </script>
</head>
<body>
    <img id="img1" src="images/02.jpg" alt="" />
</body>
</html>

 

js笔记----(运动)淡入淡出

标签:style   blog   http   io   color   ar   java   sp   div   

原文地址:http://www.cnblogs.com/juexin/p/4057267.html

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