首页 > Web开发 > 详细

js运动 淡入淡出

时间:2015-03-09 23:58:32      阅读:537      评论:0      收藏:0      [点我收藏+]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
img{
    margin-left: 200px;
    opacity: 0.3;
    alpha(opacity = 30);
    }
</style>

<script>
    window.onload = function ()
    {
        var oimg = document.getElementById(‘img1‘);
        var timer = null;

        oimg.onmouseover = function ()
        {
            touming(this,100,10)
        }

        oimg.onmouseout = function ()
        {
            touming(this,30,-10);
        }

        function touming(obj,target,speed)
        {
            clearInterval(timer);

            timer = setInterval(function ()
                {
                    var icur = Math.round(css(obj,‘opacity‘)*100);
                    if(icur == target)
                    {
                        clearInterval(timer);
                    }
                    else
                    {
                        obj.style.opacity = (icur + speed)/100;
                        obj.style.filter = ‘alpha(opacity= ‘( + icur + speed ) + ‘)‘;
                    }
                },30);
            
        }

        function css(obj,attr)
        {
            if(obj.currentStyle)
                return obj.currentStyle[attr];
            else
                return getComputedStyle(obj,false)[attr];
        }
    }
</script>
</head>

<body>
<img id="img1" src="img/1.jpg" alt="图片">
</body>
</html>

 

js运动 淡入淡出

原文:http://www.cnblogs.com/mayufo/p/4324782.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!