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>
  • 相关阅读:
    高性能反射初体验2
    高性能反射初体验1
    HTML解析原理
    QQ邮箱漂流瓶的"变化"~~
    javascript跟随滚动条滚动,onscroll事件的学习
    认识一下window.location.hash
    IE中替换a标签href属性的一个bug
    用css Sprites的时候IE6的一个小bug
    css中如何引入“非常” 字体
    [重温经典]ie6 不支持position:fix的解决方案
  • 原文地址:https://www.cnblogs.com/wy1992/p/7607868.html
Copyright © 2011-2022 走看看