Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make swiper slider responsive in angular

I have a swiper slider in my angular project. its has 4 items in desktop view. I want 1 item in the mobile view. check this link

https://stackblitz.com/edit/ngx-swiper-wrapper-demo-h9egdh?file=app/app.component.ts

Demo .ts code here

public slides = [
    'First slide',
    'Second slide',
    'Third slide',
    'Fourth slide',
    'Fifth slide',
    'Sixth slide'
  ];

  public type: string = 'component';

  public disabled: boolean = false;

  public config: SwiperConfigInterface = {
    direction: 'horizontal',
    slidesPerView: 4,
    keyboard: true,
    mousewheel: true,
    scrollbar: false,
    navigation: true,
    pagination: false
  };
like image 940
Harry Avatar asked Feb 14 '19 09:02

Harry


People also ask

How do you make a swiper slider responsive in react?

css"; import "swiper/css"; import "swiper/css/navigation"; import "swiper/css/pagination"; import "swiper/css/scrollbar"; const MainSlider = () => { return ( <Swiper // install Swiper modules breakpoints={{ 576: { width: 576, slidesPerView: 2, }, 768: { width: 768, slidesPerView: 1, }, }} modules={[Navigation, ...

What is Swiperjs?

Swiper is a JavaScript library that creates modern touch sliders with hardware-accelerated transitions (utilizing GPU to offload graphic-intensive transitions and create smoother visuals) and excellent native behavior. Swiper is available for vanilla JavaScript, Angular, React, Vue. js, and Svelte.


1 Answers

you can add a breakpoints attribute to the config JSON as:

public config: SwiperConfigInterface = {
    direction: 'horizontal',
    slidesPerView: 4,
    keyboard: true,
    mousewheel: true,
    scrollbar: false,
    navigation: true,
    pagination: false,
    breakpoints:{
       640:{
            slidesPerView: 1, 
           }
    }
};

the breakpoints can be any size you require, for more info you can check: https://github.com/nolimits4web/Swiper/blob/master/demos/380-responsive-breakpoints.html

like image 172
mahmoud abu-seini Avatar answered Sep 16 '22 22:09

mahmoud abu-seini