zoukankan      html  css  js  c++  java
  • 大图轮播

    <body>
    <div class="stage">
                <div class="left-btn">
                    </div>
                        <div class="right-btn">></div>
                        <div class="ad-banner">
                            <div class="ad" style="background-color: green;">1</div>
                            <div class="ad" style="background-color: royalblue;">2</div>
                            <div class="ad" style="background-color: red;">3</div>
                            <div class="ad" style="background-color: yellow;">4</div>
                            <div class="ad" style="background-color: gray;">5</div>
                        </div>
                </div>
        
    </body>
    * {
                    margin: 0px;
                    padding: 0px;
                }
                
                .stage {
                     300px;
                    height: 200px;
                    border: 10px solid black;
                    margin: 50px;
                    margin-left: 200px;
                    overflow: hidden;
                    position: relative;
                }
                
                .ad-banner {
                     1500px;
                    height: 200px;
                }
    .ad {
                     300px;
                    height: 200px;
                    float: left;
                    font-size: 50px;
                    line-height: 200px;
                    color: white;
                    text-align: center;
                }
    .left-btn,
                .right-btn {
                    height: 200px;
                     20px;
                    position: absolute;
                    line-height: 200px;
                    background-color: gray;
                    opacity: 0.5;
                    font-size: 20px;
                    text-align: center;
                }
    .left-btn {
                    left: 0px;
                    top: 0px;
                }
                
                .right-btn {
                    right: 0px;
                    top: 0px;
                }
    <script>
        var speed = 10;
        var count = 1;
        var arr = Array();
        document.getElementsByClassName("right-btn")[0].onclick = function() {
            arr.push(window.setInterval(moveToLeft, 10));
        }
        function moveToLeft() {
            var banner = document.getElementsByClassName("ad-banner")[0];
            if(banner.offsetLeft > count * (-300)&&count<5) {
                banner.style.marginLeft = banner.offsetLeft - speed + "px";
            } else {
                if(count<5)
                {count++;}
                for(var i in arr) {
                    window.clearInterval(arr[i]);
                }
            }
        }
        document.getElementsByClassName("left-btn")[0].onclick = function() {
            arr.push(window.setInterval(moveToRight, 10));
        }
        function moveToRight() {
            var banner = document.getElementsByClassName("ad-banner")[0];
            if(banner.offsetLeft < (count-2) * (-300)&&count>1) {
                banner.style.marginLeft = banner.offsetLeft + speed + "px";
            } else {
                if(count>1)
                {count--;}
                for(var i in arr) {
                    window.clearInterval(arr[i]);
                }
            }
        }
    </script>
  • 相关阅读:
    VSTS知识整理 荣
    扯淡 荣
    我安装了SQL Server2005后,为什么在IIS的默认站点下面并没有发现Reports? 荣
    ERROR 32000 错误 荣
    vs2012程序打包部署下载InstallShield2015LimitedEdition的下载及安装打包整套教程
    微信小程序之保持登录状态即session不改变
    微信小程序如何调用API实现数据请求wx.request()
    改版kingsmotor.cn用到的参考网站
    第一个css+div网页(太弱智了)
    超级搞笑的笑话
  • 原文地址:https://www.cnblogs.com/douchenchen/p/6638247.html
Copyright © 2011-2022 走看看