Bootstrap thumbnail slider: display the number of images based on the screen

I created a thumbnail slider for boot images. I show four images in a slider in a normal screen size.

Demo URL:

Now I want to display only one image in the thumbnail slider on the small screen in accordance with the responsive.

My current design image

My required design model

Please advise me. I am the new bee for responsive design.

My code is:

<div class="container"> <div class="span8"> <h1>Bootstrap Thumbnail Slider</h1> <div class="well"> <div id="myCarousel" class="carousel slide"> <ol class="carousel-indicators"> <li data-target="#myCarousel" data-slide-to="0" class="active"></li> <li data-target="#myCarousel" data-slide-to="1"></li> <li data-target="#myCarousel" data-slide-to="2"></li> </ol> <!-- Carousel items --> <div class="carousel-inner"> <div class="item active"> <div class="row-fluid"> <div class="span3"><a href="#x" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a></div> <div class="span3"><a href="#x" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a></div> <div class="span3"><a href="#x" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a></div> <div class="span3"><a href="#x" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a></div> </div><!--/row-fluid--> </div><!--/item--> <div class="item"> <div class="row-fluid"> <div class="span3"><a href="#x" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a></div> <div class="span3"><a href="#x" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a></div> <div class="span3"><a href="#x" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a></div> <div class="span3"><a href="#x" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a></div> </div><!--/row-fluid--> </div><!--/item--> <div class="item"> <div class="row-fluid"> <div class="span3"><a href="#x" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a></div> <div class="span3"><a href="#x" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a></div> <div class="span3"><a href="#x" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a></div> <div class="span3"><a href="#x" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a></div> </div><!--/row-fluid--> </div><!--/item--> </div><!--/carousel-inner--> <a class="left carousel-control" href="#myCarousel" data-slide="prev">β€Ή</a> <a class="right carousel-control" href="#myCarousel" data-slide="next">β€Ί</a> </div><!--/myCarousel--> </div><!--/well--> </div> </div> 
+4
source share
1 answer

I do not believe that you can achieve this solution only with CSS. Since the carousel slides are the β€œitem” class, when it goes to the small screen, it will still have 3 item slides, but with 4 vertically folded thumbnails in each slide (the span3 content of each slide will fit into the boot classes). However, there are two workarounds.

OPTION 1 - EASIER

There are two carousels. One of them is the one you showed, and the other lowers the flash fluid and object wraps and places an element on each span3. Your original receives the hidden phone class, and the new one receives the visible-phone class. In addition, you want to omit the slide indicators in the phone version to reduce clutter for many items. Below I have included a link to the jsfiddle example. Just move the vertical frame divider in the middle to the right to resize to the width of the phone (and vice versa).

http://jsfiddle.net/guydog28/tEKg8/

OPTION 2 - HARDER

The second option is much more complicated. If you should have only one carousel, you need to go into the window resizing window to find out if you now have a phone size or a phone size larger. Then you really have to manipulate the DOM so that your carousel looks like a carousel, and then again to the size of the window. So javascript will look something like this:

 $(document).ready(function () { //start the carousel $(".carousel").carousel(); //bind to window resize event to see if we've toggled //between phone and larger $(window).resize(function () { if ($(window).width() < 768) { //Phone size, manipulate DOM for phone here } else { //Not phone size, re-manipulate DOM to get back to original carousel } //Re-init carousel $(".carousel").carousel(); }); }); 
+2
source

Source: https://habr.com/ru/post/1498130/


All Articles