1

Hi I have created a Fiddle with 7 items to appear on page with the help of this question. What changes are required to JS?

My HTML:

<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>

 <div class="row">
    <div class="col-md-12">
            <div id="Carousel" class="carousel slide">
            <ol class="carousel-indicators">
                <li data-target="#Carousel" data-slide-to="0" class="active"></li>
                <li data-target="#Carousel" data-slide-to="1"></li>
                <li data-target="#Carousel" data-slide-to="2"></li>
            </ol>
            <!-- Carousel items -->
            <div class="carousel-inner">
                <div class="item active">
                  <div class="aspect"><a href="#"><img src="http://placehold.it/500/bbbbbb/fff&amp;text=1" class="img-responsive"></a></div>
                </div>
                <div class="item">
                  <div class="aspect"><a href="#"><img src="http://placehold.it/500/CCCCCC&amp;text=2" class="img-responsive"></a></div>
                </div>
                <div class="item">
                  <div class="aspect"><a href="#"><img src="http://placehold.it/500/eeeeee&amp;text=3" class="img-responsive"></a></div>
                </div>
                <div class="item">
                  <div class="aspect"><a href="#"><img src="http://placehold.it/500/f4f4f4&amp;text=4" class="img-responsive"></a></div>
                </div>
                <div class="item">
                  <div class="aspect"><a href="#"><img src="http://placehold.it/500/fcfcfc/333&amp;text=5" class="img-responsive"></a></div>
                </div>
                <div class="item">
                  <div class="aspect"><a href="#"><img src="http://placehold.it/500/f477f4/fff&amp;text=6" class="img-responsive"></a></div>
                </div>
                <div class="item">
                  <div class="aspect"><a href="#"><img src="http://placehold.it/500/f477f4/fff&amp;text=7" class="img-responsive"></a></div>
                </div>
                <div class="item">
                  <div class="aspect"><a href="#"><img src="http://placehold.it/500/f477f4/fff&amp;text=8" class="img-responsive"></a></div>
                </div>
                <div class="item">
                  <div class="aspect"><a href="#"><img src="http://placehold.it/500/f477f4/fff&amp;text=9" class="img-responsive"></a></div>
                </div>
                <div class="item">
                  <div class="aspect"><a href="#"><img src="http://placehold.it/500/f477f4/fff&amp;text=10" class="img-responsive"></a></div>
                </div>
                <div class="item">
                  <div class="aspect"><a href="#"><img src="http://placehold.it/500/f477f4/fff&amp;text=11" class="img-responsive"></a></div>
                </div>
                <div class="item">
                  <div class="aspect"><a href="#"><img src="http://placehold.it/500/f477f4/fff&amp;text=12" class="img-responsive"></a></div>
                </div>
            </div><!--.carousel-inner-->
              <a data-slide="prev" href="#Carousel" class="left carousel-control">‹</a>
              <a data-slide="next" href="#Carousel" class="right carousel-control">›</a>
            </div><!--.Carousel-->

        </div>
</div>

My CSS:

                body{padding-top:20px;}
            .carousel {
                margin-bottom: 0;
                padding: 0 40px 30px 40px;
            }
            .aspect{
                width: calc(100%/7 - 10px) !important;
                padding:0 5px;
                float:left;
            }
            /* The controlsy */
            .carousel-control {
                left: -12px;
                height: 40px;
                width: 40px;
                background: none repeat scroll 0 0 #222222;
                border: 4px solid #FFFFFF;
                border-radius: 23px 23px 23px 23px;
                margin-top: 90px;
            }
            .carousel-control.right {
                right: -12px;
            }
            /* The indicators */
            .carousel-indicators {
                right: 50%;
                top: auto;
                bottom: -10px;
                margin-right: -19px;
            }
            /* The colour of the indicators */
            .carousel-indicators li {
                background: #cecece;
            }
            .carousel-indicators .active {
            background: #428bca;
            }

The JS I've used:

$(document).ready(function() {
    $('#Carousel').carousel({
        interval: false
    })
});

$(window).ready(function(){
    $('.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));
    }
    else {
        $(this).siblings(':first').children(':first-child').clone().appendTo($(this));
    }
    }); 
}); 

I need to slide single item using click and touch (in mobile).

Ali Soltani
  • 9,589
  • 5
  • 30
  • 55
Shubh
  • 93
  • 1
  • 9
  • The solution is provided as answer in the question you put as reference. For swipe feature checkout this [answer](https://stackoverflow.com/questions/21349984/how-to-make-bootstrap-carousel-slider-use-mobile-left-right-swipe) – Amit Kumar Jul 21 '18 at 09:11
  • @Amit What will the javascript code? – Shubh Jul 25 '18 at 05:48
  • JavaScript for what? Swipe feature? – Amit Kumar Jul 25 '18 at 07:34
  • Currently 3 slides are appearing in carousel. It should display 7 slides in the page. https://jsfiddle.net/shubh1976/25gx341p/8/ – Shubh Jul 25 '18 at 07:45
  • Bootstrap at one time display one `div` with class `.item`. What you are doing in JavaScript code is appending the data you need in `div` with class `.item`. Currently you are doing it twice. You can do it seven times by JavaScript or do it in HTML itself. I have updated HTML of your [code](https://jsfiddle.net/25gx341p/20/) to get the same effect. – Amit Kumar Jul 25 '18 at 09:24
  • Thanks that I have already experimented, But my requirement is to move item one by one not 7 items at once. Can you help? – Shubh Jul 26 '18 at 07:28

0 Answers0