How to change the number of items displayed for different screen sizes

Viewed 2442

I'm trying to find a way to change the number of carouselVisible items for different screen sizes. I want in a screen resolution of 768px to show 3 items and when you scale down in 360 to have 1 item.

Is that possible?

Demo

jquery

$('#carousel').cycle({
allowWrap: true,
carouselVisible: 5,
prev: '#prev',
next: '#next',
carouselFluid: true,
timeout: 0,
slides: 'article',
fx: 'carousel'
});

var slideshows1 = $('#carousel').on('cycle-next cycle-prev', function (e, opts) {
slideshows1.not(this).cycle('goto', opts.currSlide);
});
var slideshows2 = $('#carousel1').on('cycle-next cycle-prev', function (e, opts) {
slideshows2.not(this).cycle('goto', opts.currSlide);
});
$('#carousel article').click(function () {
var count = $("#carousel1 .readmore").length - 1;
var selectedIndex = $('#carousel').data('cycle.API').getSlideIndex(this);
var index = selectedIndex<count ? selectedIndex: (selectedIndex-count)%count;
slideshows1.cycle('goto', index);
slideshows2.cycle('goto', index);
});

Html

        <div class="service">
         <h1>Lead1</h1>
    </div>
</article>
<article>
    <div class="service">
         <h1>Lead2</h1>
    </div>
</article>
</div>
<div id="carousel1" data-allow-wrap="true" data-cycle-prev="#prev" data-cycle-next="#next" class="cycle-slideshow" data-cycle-timeout="0" data-cycle-manual-fx="scrollHorz" data-cycle-slides=".readmore">
<div class="readmore">
     <h2 class="lead">Lead</h2>

    <p>Testing some text right here</p> <a class="cta" href="#">Läs mer</a>

</div>
<div class="readmore">
     <h2 class="lead">Lead1</h2>

    <p>Testing some text right here</p> <a class="cta" href="#">Läs mer</a>

</div>
<div class="readmore">
     <h2 class="lead">Lead2</h2>

    <p>Testing some text right here</p> <a class="cta" href="#">Läs mer</a>

</div>
</div>
<div id="next">next</div>
<div id="prev">prev</div>
2 Answers

you can use easily swiperjs and you can set breakpoints. from example

    <Swiper
    slidesPerView={1}
    spaceBetween={10}
    pagination={{
      clickable: true
    }}
    breakpoints={{
      "640": {
        slidesPerView: 2,
        spaceBetween: 20
      },
      "768": {
        slidesPerView: 4,
        spaceBetween: 40
      },
      "1024": {
        slidesPerView: 5,
        spaceBetween: 50
      }
    }}
    className="mySwiper"
  >
    <SwiperSlide>Slide 1</SwiperSlide>
    <SwiperSlide>Slide 2</SwiperSlide>
    <SwiperSlide>Slide 3</SwiperSlide>
    <SwiperSlide>Slide 4</SwiperSlide>
    <SwiperSlide>Slide 5</SwiperSlide>
    <SwiperSlide>Slide 6</SwiperSlide>
    <SwiperSlide>Slide 7</SwiperSlide>
    <SwiperSlide>Slide 8</SwiperSlide>
    <SwiperSlide>Slide 9</SwiperSlide>
  </Swiper>
Related