美文网首页
js运动之"焦点图"

js运动之"焦点图"

作者: RL空RLR空L | 来源:发表于2018-01-17 09:21 被阅读0次
    ed.jpg
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
        <style>
            #div1 {
                width: 200px;
                height: 200px;
                background:red;
            /*兼容性问题,filter:alpha(opacity:30);给IE。opacity:0.3;给火狐谷歌用。*/
                filter:alpha(opacity:30);
                opacity:0.3;
            }
        </style>
        <script>
            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(iTarget){
                var oDiv=document.getElementById('div1');
                clearInterval(timer);
                timer=setInterval(function(){
                    var speed=0;
                    if(alpha<iTarget){
                        speed=5;
                    }else{
                        speed=-5;
                    }
                    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>
    

    相关文章

      网友评论

          本文标题:js运动之"焦点图"

          本文链接:https://www.haomeiwen.com/subject/khsyoxtx.html