An open API service indexing awesome lists of open source software.

https://github.com/mrvcoder/swiperjs-dynamic-responsive

with this piece of code you can set sliders of swiper.js margin dynamically base on width of slider container
https://github.com/mrvcoder/swiperjs-dynamic-responsive

Last synced: 11 months ago
JSON representation

with this piece of code you can set sliders of swiper.js margin dynamically base on width of slider container

Awesome Lists containing this project

README

          

# swiperjs-dynamic-responsive

with using this function in your code you can make the sliders that created with [swiper.j](https://swiperjs.com/) from this 👇.

https://user-images.githubusercontent.com/49777789/182134303-d517c613-0747-46ac-bede-d0fb615697d0.mp4

to this :) 👇

https://user-images.githubusercontent.com/49777789/182134278-2732dfdb-e7d6-44d1-9422-3a68e19a9193.mp4

## how to use function

lets say that you have this code to create slider

**html code :**
```



Slide 1

Slide 2

Slide 3

Slide 4

Slide 5

Slide 6

Slide 7

Slide 8

Slide 9



```

**JavaScript :**
```
export function MySlider(){

let swiper = new Swiper(".mySwiper", {
slidesPerView:'auto',
spaceBetween: 50,
});

}
```

to use this code you should first add our function in your project then you should change the previues code to this :

```
export function MySlider(){

let [space , max] = MakeResponsiveSliders(document.querySelector('.mySwiper'),
{
margin:20
}
)

let swiper = new Swiper(".mySwiper", {
slidesPerView:'auto',
spaceBetween: space,
centeredSlides: false
});

swiper.snapGrid[swiper.snapGrid.length-1]=swiper.snapGrid[swiper.snapGrid.length-1]+space

}
```
in this code **MakeResponsiveSliders** is our function and you should pass some parameters
- #1 first parameter is your slider container html obj
- #2 second parameter is an object for seting some minimal settings..

for now the minimal setting object only gets **margin** in **px** .