簡體   English   中英

Bootstrap輪播:如何知道輪播暫停時是哪個滑塊

[英]Bootstrap carousel: how to know which slider it is when carousel is paused

我有一個輪播幻燈片演示,可以開始(在瀏覽器刷新時)和暫停( myBtn2 )。 暫停時,我需要知道當前的滑塊是什么。 我怎么做? 在我的代碼下面

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet"
        href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script
        src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script
        src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="./style.css">
    <script src="main.js"></script>
    <style>
    .carousel-inner>.item>img, .carousel-inner>.item>a>img {
        width: 70%;
        margin: auto;
    }
    </style>
    </head>
    <body>

        <div class="container">

            <button type="button" id="myBtn2" class="btn btn-danger btn-lg">Set</button>
            <br>
            <br>
            <div id="myCarousel" class="carousel slide" data-interval="2000">
                <!-- Indicators -->
                <ol class="carousel-indicators">
                    <li class="item1 active"></li>
                    <li class="item2"></li>
                    <li class="item3"></li>
                    <li class="item4"></li>
                </ol>

                <!-- Wrapper for slides -->
                <div class="carousel-inner" role="listbox">
                    <div class="item active">
                        <img src="jack-spades.png" alt="Jake Spade" width="460"
                            height="345">
                    </div>

                    <div class="item">
                        <img src="jack_dimond.jpg" alt="Jack Diamond" width="460"
                            height="345">
                    </div>

                    <div class="item">
                        <img src="queen.jpg" alt="Queen" width="460" height="345">
                    </div>

                    <div class="item">
                        <img src="queen_spades.jpg" alt="Queen Spade" width="460"
                            height="345">
                    </div>
                </div>

                <!-- Left and right controls -->
                <a class="left carousel-control" href="#myCarousel" role="button">
                    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                    <span class="sr-only">Previous</span>
                </a>
                <a class="right carousel-control" href="#myCarousel" role="button">
                    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                    <span class="sr-only">Next</span>
                </a>
            </div>
        </div>

        <script>
            $(document).ready(function() {
                // Activate Carousel
                $("#myCarousel").carousel("cycle");

                // Click on the button to stop sliding
                $("#myBtn2").click(function() {
                    $("#myCarousel").carousel("pause");
                });

                // Enable Carousel Indicators
                $(".item1").click(function() {
                    $("#myCarousel").carousel(0);
                });
                $(".item2").click(function() {
                    $("#myCarousel").carousel(1);
                });
                $(".item3").click(function() {
                    $("#myCarousel").carousel(2);
                });
                $(".item4").click(function() {
                    $("#myCarousel").carousel(3);
                });

                // Enable Carousel Controls
                $(".left").click(function() {
                    $("#myCarousel").carousel("prev");
                });
                $(".right").click(function() {
                    $("#myCarousel").carousel("next");
                });
            });
        </script>

    </body>
    </html>

$(“ div.active”)或$(“ li.active”)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM