Solution: Last slide not getting active when 'slidePerView' set to 'auto'.
See original GitHub issueI currently experienced the same problems like as many people did and also looked through the issues but no results. https://github.com/nolimits4web/swiper/issues/2571, https://github.com/nolimits4web/swiper/issues/1257, https://github.com/nolimits4web/swiper/issues/534 Finally, I found out a way to do it, a better way to do it guys!.
By setting the snapGrid settings as same as the slidesGrid settings after the swiper initialized.
And then the swiper will work as what you expected.
const swiper = new Swiper(
'.awesome-swiper',
{
init: false,
direction: 'horizontal',
speed: 700,
slidesPerView: 'auto',
spaceBetween: 80,
}
);
swiper.init();
swiper.snapGrid[swiper.snapGrid.length - 1] = swiper.slidesGrid[swiper.slidesGrid.length - 1];
or even completely replacing it by cloning the settings.
// can do this way
swiper.snapGrid = swiper.slidesGrid.slice(0);
// or ES6 way
swiper.snapGrid = [...swiper.slidesGrid];
Update: 2020-11-18
You will need to update the snapGrid when responsive by using built-in Events.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:13
- Comments:13
Top Results From Across the Web
Swiper JS Slides not Sliding all the way the left - Stack Overflow
I have tried setting loop:true but this centres my first slide and displays a partial at the left that I don't want at...
Read more >SwiperOptions | Swiper - v8.4.5
If true , then active slide will be centered without adding gaps at the beginning and end of slider. Required centeredSlides: true ....
Read more >Last slide never becomes active when using Auto Slides Per ...
When the swiper is set to "slidesPerView: 'auto'" and the slides have different widths, the last slide doesn't seem to get as the...
Read more >Set slidesPerView value with decimals? Or maybe override it ...
Hi, REALLY thank you for your quick answer! Well, I've tried to set “Centered Slides” option on and now my active slide is...
Read more >Using .last() to check if we're on the last slide - Codecademy
I couldn't get your code to work (could be me) but I did succeed with this: ... Polepeddi made this not auto-dropdown, but...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
this work for me, but with a little adjustment: I placed this line
this.snapGrid = [...this.slidesGrid];inside of thereachEndswiper event, like this: