Locked number of slides

JS:

  $('.slider2').mbSlider({
    slideWidth: 300,
    minSlides: 2,
    maxSlides: 2,
    slideMargin: 10
  });
});

HTML:

<div class="slider2">
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=1472600729"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=5554128017"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=5109506840"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=9962836428"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=5981394271"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=5960453746"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=5555914904"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=2821362323"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=4262594717"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=9411467808"></div>
</div>

Here we want to always display 2 slides no matter the screen size. Therefore we set both minSlides and maxSlides to 2. Resize your browser to see that no matter how large or small the screen becomes, 2 slides are always displayed.

Start on slide number...

JS:

  $('.slider6').mbSlider({
    slideWidth: 300,
    minSlides: 2,
    maxSlides: 3,
    startSlide: 2,
    slideMargin: 10
  });
});

HTML:

<div class="slider6">
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=9204923192"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=2106797836"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=6877286752"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=7965781831"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=2257001201"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=8237535808"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=3990430975"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=9912919255"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=2607611456"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=5126798883"></div>
</div>

This is a tricky one smiley Here we specify a startSlide value of 2. This can be a little misleading as this does not refer to slide #2, but it refers to pager #2. Since slides and pagers are zero-based, we are telling the carousel to start on the third pager (remember that 2 in a zero-based world is the third element). Similar to the moveSlides explanation above, this occurs so that the carousel can stay in sync with the pager and prevents the markup from becoming unweildy.

Slide width

JS:

  $('.slider3').mbSlider({
    slideWidth: 5000,
    minSlides: 2,
    maxSlides: 4,
    slideMargin: 10
  });
});

HTML:

<div class="slider3">
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=6278633118"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=1648102239"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=2728173471"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=4766243432"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=4578692002"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=7683308752"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=8843478107"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=9473229919"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=5593088140"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=8856132989"></div>
</div>

Here we intentionally set a slideWidth larger than the available space. In this case, the slider defaults to the minSlide value, and scales appropriately.

Move number of slides

JS:

  $('.slider4').mbSlider({
    slideWidth: 300,
    minSlides: 2,
    maxSlides: 3,
    moveSlides: 1,
    slideMargin: 10
  });
});

HTML:

<div class="slider4">
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=5183313005"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=7485454208"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=3802580461"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=4674350948"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=2459033519"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=4415422894"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=3170113321"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=5784367649"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=1229920304"></div>
  <div class="slide"><img src="https://unsplash.it/1280/720?random&p=2133510788"></div>
</div>

The configuration option moveSlides tells the carousel how many slides to move each time next or prev is fired. If no value is supplied for moveSlides, the carousel will use the number of visible slides for this value.

Torna all'inizio