zoukankan      html  css  js  c++  java
  • 用加减边距写图片轮播

    css样式:

     <style>
            #tu {
                 800px;
                height: 500px;
                position: relative;
                overflow: hidden;
                margin: 30px auto;
            }
    
            #ta {
                 4000px;
                height: 500px;
                margin-left: 0px;
            }
    
            .lie {
                 800px;
                height: 500px;
                background-size: contain;
            }
        </style>

    body:

    <body>
        <form id="form1" runat="server">
            <div id="tu" onmouseover="pause()" onmouseout="contin()">
                <table id="ta" cellpadding="0" cellspacing="0">
                    <tr height="500px">
                        <td class="lie">
                            <img src="1.jpg" width="800" height="100%" /></td>
                        <td class="lie">
                            <img src="2.jpg" width="800" height="100%" /></td>
                        <td class="lie">
                            <img src="3.jpg" width="800" height="100%" /></td>
                        <td class="lie">
                            <img src="4.jpg" width="800" height="100%" /></td>
                        <td class="lie">
                            <img src="5.jpg" width="800" height="100%" /></td>
                    </tr>
                </table>
                <div id="zuo" style=" 30px; height: 50px; background-color: black; float: left; top: 200px; position: absolute; opacity: 0.5;"></div>
                <div id="you" style=" 30px; height: 50px; background-color: black; left: 770px; top: 200px; position: absolute; opacity: 0.5;"></div>
            </div>
    
        </form>
    </body>

    js代码:

    <script>
        document.getElementById("ta").style.marginLeft = "0px";
        function huan() {
            var tp = document.getElementById("ta");
            var a = parseInt(tp.style.marginLeft);
            if (a <= -3200) {
                tp.style.marginLeft = "0px";
    
            }
            else {
                tp.style.marginLeft = (a - 800) + "px";
    
            }
          
        }
        var id = window.setInterval(huan, 2000);
    
        function pause() {
            window.clearInterval(id);
        }
        function contin() {
            id = window.setInterval(huan, 2000);
        }
        document.getElementById('zuo').onclick = function () {
            var tp = document.getElementById("ta");
            var a = parseInt(tp.style.marginLeft);
            if (a >= 0)
            { tp.style.marginLeft = "-3200px"; }
            else
            { tp.style.marginLeft = (a + 800) + "px"; }
        }
        document.getElementById('you').onclick = function () {
            var tp = document.getElementById("ta");
            var a = parseInt(tp.style.marginLeft);
            if (a <= -3200) {
                tp.style.marginLeft = "0px";
    
            }
            else {
                tp.style.marginLeft = (a - 800) + "px";
    
            }
        }
    
    </script>
  • 相关阅读:
    poj 1015 Jury Compromise(背包+方案输出)
    最长公共上升子序列 (poj 2127) (Greatest Common Increasing Subsequence)
    轮廓线DP:poj 2279 Mr. Young's Picture Permutations
    LCS的几种求法
    POJ 1737 Connected Graph(高精度+DP递推)
    Cats transport(codeforces311B)(斜率优化)
    高精度(压位+判负数+加减乘+读写)
    洛谷 P2257 YY的GCD
    [POI2007]ZAP-Queries (莫比乌斯反演+整除分块)
    [SDOI2010]古代猪文 (欧拉,卢卡斯,中国剩余)
  • 原文地址:https://www.cnblogs.com/wy1992/p/7607868.html
Copyright © 2011-2022 走看看