zoukankan      html  css  js  c++  java
  • jQuery 实现焦点图(banner)

    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
        <meta charset="utf-8" />
        <script src="JS/jquery-3.3.1.min.js"></script>
        <style>
            * {
                margin: 0;
                padding: 0;
                list-style: none;
            }
    
            #div1 {
                 100%;
                background: url(1.jpeg) center top no-repeat;
                height: 368px;
                position: relative;
                text-align: center;
            }
    
                #div1 div {
                     30px;
                    height: 80px;
                    background-color: #000;
                    position: absolute;
                    color: #fff;
                    font-size: 40px;
                    line-height: 80px;
                    text-align: center;
                }
    
            #leftbtn {
                top: 144px;
            }
    
            #rightbtn {
                top: 144px;
                right: 0px;
            }
    
            #nav {
                position: absolute;
                 350px;
                top: 345px;
                left: 50%;
                margin-left: -130px;
            }
    
                #nav li {
                     40px;
                    height: 4px;
                    float: left;
                    background-color: #fff;
                    margin-left: 10px;
                }
        </style>
        <script>
            function style($) {
                $(".drop").css("backgroundColor", "#fff");
            }
    
    
            $(function () {
                var imgs = ["1.jpeg", "2.jpeg", "3.jpeg", "4.jpeg", "5.jpeg"];
                $(".drop").eq(0).css("backgroundColor", "#000");
                $(".drop").each(function (i) {
                    $(".drop").eq(i).mouseover(function () {
                        style($);
                        $(this).css("backgroundColor", "#000");
                        $("#div1").css("backgroundImage", "url(" + imgs[i] + ")");
                    });
                });
    
    
                var index = 0;            
                $("#rightbtn").click(function () {                
                    index++;         
                    if (index > imgs.length-1) {
                        index = 0;
                    }
                    $("#div1").css("backgroundImage", "url(" + imgs[index] + ")");
                    style($);
                    $(".drop").eq(index).css("backgroundColor", "#000");
                    clearInterval(timeout);
                    timeout = setInterval(show2, 2000);             
                })
    
    
                var index = imgs.length - 1;
                $("#leftbtn").click(function () {
                    index--;
                    if (index < 0) {
                        index = imgs.length - 1;
                    }
                    $("#div1").css("backgroundImage", "url(" + imgs[index] + ")");
                    style($);
                    $(".drop").eq(index).css("backgroundColor", "#000");
                    clearInterval(timeout);
                    timeout = setInterval(show2, 2000);
                })
    
    
                var i = 0;
                function show1() {
                    $("#div1").css("backgroundImage", "url(" + imgs[i] + ")");
                    style($);
                    $(".drop").eq(i).css("backgroundColor", "#000");
                    i++;
                    if (i > imgs.length - 1) {
                        i = 0;
                    }             
                }
                var index=0;
                function show2() {               
                    style($);
                    $(".drop").eq(index).css("backgroundColor", "#000");
                    $("#div1").css("backgroundImage", "url(" + imgs[index] + ")");
                    index++;
                    if (index> imgs.length - 1) {
                        index = 0;
                    }
                   
                }
                var timeout = setInterval(show1, 2000);//每隔2秒改变一次
    
                $(".drop").mouseover(function () {
                    clearInterval(timeout);
                    timeout = setInterval(show2, 2000);
                    index= $(this).index(".drop");
                })         
            })
        </script>
    </head>
    <body>
        <div id="div1">
            <a href="#"> <div id="leftbtn"><</div></a>
            <a href="#"><div id="rightbtn">></div></a>
        </div>
        <ul id="nav">
            <li class="drop"></li>
            <li class="drop"></li>
            <li class="drop"></li>
            <li class="drop"></li>
            <li class="drop"></li>
        </ul>
    
    </body>
    </html>
  • 相关阅读:
    【BZOJ】1726 [Usaco2006 Nov]Roadblocks第二短路
    【BZOJ】1666 [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
    【BZOJ】1699 [Usaco2007 Jan]Balanced Lineup排队
    【BZOJ】1477 青蛙的约会
    【BZOJ】1385 [Baltic2000]Division expression
    【算法】数学
    【NOIP】提高组2012 同余方程
    【BZOJ】1096 [ZJOI2007]仓库建设
    【算法】动态规划
    【LA】5135 Mining Your Own Business
  • 原文地址:https://www.cnblogs.com/zhang1997/p/8358687.html
Copyright © 2011-2022 走看看