简体   繁体   English

小于3的项目会重复执行Bootstrap轮播缩略图

[英]Bootstrap carousel thumbnail repeat when item lesser than 3

I am using bootstrap carousel thumbnail. 我正在使用引导轮播缩略图。 Currently the slider clone after complete the last slider . 当前,在完成最后一个滑块之后,该滑块会克隆。 I need to stop repeating item when my slider count less than 3. I have tried the below script. 当滑块的数量少于3时,我需要停止重复项目。我尝试了以下脚本。 Anyone help me to achieve this . 任何人都可以帮助我实现这一目标。

<div id="carousel" class="carousel slide" data-ride="carousel" data-interval="false">
        <div class="carousel-inner">
            <div class="item active">
                <img src="images/homogeneous/marvel-stone/marvel-stone-detail.jpg" alt="">
            </div>
        </div>
    </div>
    <div class="clearfix">
        <div id="myCarousel" class="carousel slide" data-interval="false">
            <div class="carousel-inner">
                <div class="item active">                
                    <div class="thumb"><img src="images/homogeneous/marvel-stone/marvel-stone-thumb1.png" alt=""></div>
                </div>
                <div class="item">
                    <div class="thumb"><img src="images/homogeneous/marvel-stone/marvel-stone-thumb2.png" alt=""></div>
                </div>
                <div class="item">
                    <div class="thumb"><img src="images/homogeneous/marvel-stone/marvel-stone-thumb3.png" alt=""></div>
                </div>
                <div class="item">
                    <div class="thumb"><img src="images/homogeneous/marvel-stone/marvel-stone-thumb4.png" alt=""></div>
                </div>
            </div>
            <!-- /carousel-inner -->
            <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
           <span class="glyphicon glyphicon-chevron-left"></span>
        </a>
            <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
           <span class="glyphicon glyphicon-chevron-right"></span>
        </a>
        </div>
        <!-- /myCarousel -->
    </div>
<!-- /clearfix --> 

below script I wast tried for 3 items. 下面的脚本我没有尝试过3个项目。 How to make it for one and two items with simplified script. 如何使用简化的脚本制作一个和两个项目。

 $('#myCarousel').carousel({
     interval: false
 });
 var totalItems = $('.item').length;
 if (totalItems > 3) {
     //alert();
     $('.carousel .item').each(function() {
         var next = $(this).next();
         if (!next.length) {
             next = $(this).siblings(':first');
         }
         next.children(':first-child').clone().appendTo($(this));

         if (next.next().length > 0) {

             next.next().children(':first-child').clone().appendTo($(this)).addClass('rightest');

         } else {
             $(this).siblings(':first').children(':first-child').clone().appendTo($(this));

         }
     });
 } else {

     //what to be here
 }

[my code link] [我的代码链接]

您可能缺少一些CSS,请尝试使用以下代码进行实验: https : //www.bootply.com/124854#

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM