Swiper: Lazy load + slidesPerView:"auto" not work together!

Created on 21 Nov 2020  路  4Comments  路  Source: nolimits4web/swiper

This is a very old issue but has not yet been fixed.
Currently, it is not possible to use lazy load + slidesPerView:"auto" together. :(

--

What you did

Tried to use lazy loading with slidesPerView: "auto".

var mySwiper = new Swiper(".swiper-container", {
  slidesPerView: "auto",
  preloadImages: false,
  watchSlidesProgress: true,
  watchSlidesVisibility: true,
  lazy: true,

  navigation: {
    nextEl: ".swiper-button-next",
    prevEl: ".swiper-button-prev"
  }
});

Expected Behavior

  • Images should only load when visible
  • Navigation arrows should work

Actual Behavior

  • All images load right away
  • Navigation arrows stay deactivated
  • As soon as you resize the page it seems to work again.

You can see this at https://codepen.io/mrWilson123/pen/JjKQEKj

You can also change slidesPerView: "auto" to slidesPerView: 2 and you will see images lazy load correctly, and the navigation works again.

Most helpful comment

add this to your options:

on: {
        lazyImageReady: (swiper) => {swiper.update()}
    }

-> https://github.com/nolimits4web/swiper/issues/3929#issuecomment-723056648

All 4 comments

Same with issue 1679.

Yes, but it doesn't help me further. As you can see, this problem has existed for years. There is still no solution.

add this to your options:

on: {
        lazyImageReady: (swiper) => {swiper.update()}
    }

-> https://github.com/nolimits4web/swiper/issues/3929#issuecomment-723056648

Thank you, @moevbiz. Your answer was very helpful. It seems to be working now. 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hiyelbaz picture hiyelbaz  路  21Comments

fregiese picture fregiese  路  17Comments

EdicionPG picture EdicionPG  路  17Comments

almothafar picture almothafar  路  19Comments

SantzDesign picture SantzDesign  路  50Comments