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>
  • 相关阅读:
    ATA/SATA/SCSI/SAS/FC总线简介
    RAID卡
    解读Gartner《2015年度新兴技术成熟度曲线报告》
    linux 下 取进程占用内存(MEM)最高的前10个进程
    网站用域名能访问,用域名IP不能访问的原因分析
    iis7下iis安全狗不能用怎么办(安装iis6兼容性)
    4M宽带一般最大的下载速度是多少?
    U盘安装操作系统
    windows7实现打印机共享的方法
    windows7系统下如何安装windows xp系统(无法识别硬盘,删除隐藏分区)
  • 原文地址:https://www.cnblogs.com/wy1992/p/7607868.html
Copyright © 2011-2022 走看看