首页 > 其他 > 详细

左右滚动的电影画布

时间:2019-07-30 11:07:21      阅读:53      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
    <head>
<meta charset="utf-8">
        <style type="text/css">
            .box{
                width: 660px;
                height: 500px;
                margin: 100px auto;
                overflow: hidden;
                position: relative;
            }
            .box span{
                width: 330px;
                height: 500px;
                position: absolute;
                top: 0;
                cursor: pointer;
            }
            .box #left{
                left: 0;
            }
            .box #right{
                left: 330px;
            }
            .box #pic{
                position: absolute;
                top: 0;
            }
        </style>
        <script type="text/javascript">
            function $(id){return document.getElementById(id);}         
            window.onload = function(){
                var step = 20;
                var left = 0;
                $(‘right‘).onmouseover = function(){
                    // alert($(‘pic‘).timer);
                    if($(‘pic‘).timer){
                        clearInterval($(‘pic‘).timer); 
                    }
                    $(‘pic‘).timer = setInterval(function(){
                        if(left > -1520){                      
                            left -= step;
                            $(‘pic‘).style.left = left + ‘px‘;
                        }
                    }, 50);                   
                }
                $(‘left‘).onmouseover = function(){
                    // alert($(‘pic‘).timer);
                    if($(‘pic‘).timer){
                        clearInterval($(‘pic‘).timer)
                    }
                    $(‘pic‘).timer = setInterval(function(){
                        if(left < 0){
                            left += step;
                            $(‘pic‘).style.left = left + ‘px‘;
                        }
                    }, 50);                   
                }
                var box = document.getElementsByClassName(‘box‘)[0];
                box.onmouseout = function(){
                    clearInterval($(‘pic‘).timer);
                }
            }
        </script>
    </head>
    <body>
        <div class="box">
            <img src="imgs/mj.jpg" id="pic">
            <span id="left"></span>
            <span id="right"></span>
        </div>
    </body>
</html>
技术分享图片

左右滚动的电影画布

原文:https://www.cnblogs.com/mmit/p/11268737.html

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