zoukankan      html  css  js  c++  java
  • 图片轮播——点击切换

    效果图

    HTML代码

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title> 广告图片轮播切换</title>
        <link rel="stylesheet" href="css/style.css">
    </head>
    <body>
    <div class="adver">
        <ul>
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
            <li>6</li>
        </ul>
        <div class="arrowLeft"><</div>
        <div class="arrowRight">></div>
    </div>
    
    </body>
    </html>

    jQuery代码

    <script src="js/jquery-3.2.1.js" type="text/javascript"></script>
    <script>
        $(document).ready(function () {
            $(".adver").mouseover(function () {
                $(".arrowLeft").show();
                $(".arrowRight").show();
            }).mouseout(function () {
                $(".arrowLeft").hide();
                $(".arrowRight").hide();
            })
            var i = 0;
            var path = ["adver01.jpg", "adver02.jpg", "adver03.jpg", "adver04.jpg", "adver05.jpg", "adver06.jpg"];
            $(".arrowRight").click(function () {
                if (i == path.length - 1) {
                    i=0;
                } else {
                    i++;
                    var str = "images/" + path[i];
                    $(".adver").css({"background": "url(" + str + ")"});
                    $("li:nth-of-type("+(i+1)+")").css({"background":"orange"});
                    $("li:nth-of-type("+(i+1)+")").siblings().css({"background":"#333"});
                }
            })
            $(".arrowLeft").click(function () {
                if (i == 0) {
                    i=6;
                } else {
                    i--;
                    var str = "images/" + path[i];
                    $(".adver").css({"background": "url(" + str + ")"});
                    $("li:nth-of-type("+(i+1)+")").css({"background":"orange"});
                    $("li:nth-of-type("+(i+1)+")").siblings().css({"background":"#333"});
                }
            })
        })
    
    </script>

    CSS代码

    ul,li{padding: 0;margin: 0; list-style: none;}
    .adver{margin: 0 auto;  700px; overflow: hidden; height: 454px; position: relative; background: url("../images/adver01.jpg");}
    ul{position: absolute; bottom:10px; z-index: 100;  100%; text-align: center;}
    ul li{display: inline-block; font-size: 10px; line-height: 20px; font-family: "微软雅黑"; margin: 0 1px;  20px; height: 20px; border-radius: 50%; background: #333333; text-align: center; color: #ffffff;}
    .arrowLeft,.arrowRight{
        position: absolute;
         30px;
        background:rgba(0,0,0,0.2);
        height: 50px;
        line-height: 50px;
        text-align: center;
        top:200px;
        z-index: 150;
        font-family: "微软雅黑";
        font-size: 28px;
        font-weight: bold;
        cursor: pointer;
        display: none;
    }
    .arrowLeft{left: 10px;}
    .arrowRight{right: 10px;}
    li:nth-of-type(1){
        background: orange;
    }
    

      

  • 相关阅读:
    Java学习笔记8(面向对象3:接口)
    面向对象2(继承,抽象类)
    java学习笔记6(面向对象1:概念,private)
    排序方法-循环和数组练习
    ArrayList方法综合练习
    Eclipse的配置
    集合(ArrayList)简述
    java学习笔记5(方法)
    数据结构9——最小生成树
    数据结构8——图的遍历
  • 原文地址:https://www.cnblogs.com/binglong180/p/7623566.html
Copyright © 2011-2022 走看看