码迷,mamicode.com
首页 > 其他好文 > 详细

实现基本的图片淡入淡出的效果

时间:2015-12-09 21:34:44      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            #img1 {
                filter: alpha(opacity:20);
                opacity: 0.2;
            }
        </style>
        <script>
            window.onload = function(){
                var oImg = document.getElementById(‘img1‘);
                oImg.onmouseover = function(){
                    startMove(100);
                }
                oImg.onmouseout = function(){
                    startMove(20);
                }
            }
            var alpha = 20;
            var timer = null;
            function startMove(iTarget){
                var oImg = document.getElementById(‘img1‘);
                var iSpeed = 0;
                clearInterval(timer);
                timer = setInterval(function(){
                    if (alpha < iTarget) {
                        iSpeed = 2;
                    } else {
                        iSpeed = -2;
                    }

                    if (alpha == iTarget) {
                        clearInterval(timer);
                    } else {
                        alpha += iSpeed;
                        oImg.style.filter = ‘alpha(opacity:‘+ alpha +‘)‘;
                        oImg.style.opacity = alpha/100;
                    }
                }, 30);
            }
        </script>
    </head>
    <body>
        <img id="img1" src="images/bg_agency_banner.jpg" height="339" width="1360"/>
    </body>
</html>

 

实现基本的图片淡入淡出的效果

标签:

原文地址:http://www.cnblogs.com/jimmzy/p/5034264.html

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