Swiper: Lazy Loading Swiper Jumps

Created on 6 Nov 2020  路  7Comments  路  Source: nolimits4web/swiper

This is a (multiple allowed):

  • [x] bug
  • [ ] enhancement
  • [ ] feature-discussion (RFC)

What you did

Create a swiper with lazy loading. Offset of the images is wrong, unless I resize the window when everything is loaded. ( The same appears when adding a video to a slide).

Expected Behavior

Correct Image offset, also with { centeredSlides: true }

Actual Behavior

offset is wrong

All 7 comments

From example, it looks like this solves it for you, right?

          lazyImageReady: function() {
            console.log("lazy image ready");
            this.updateSlides();
            this.slideTo(this.activeIndex, 0, false);
          }

unfortunately not. see a video here: https://nx5024.your-storageshare.de/s/YXW3p79HsHnJr4T. It only works correctly after resizing the browser window. Also does not work without data-srcset.

@niklasp
https://skr.sh/v50bBm7aAsu?a
Am I testing it wrong?

try:

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

https://stackblitz.com/edit/lazy-loading-swiper-bug-cpdyap?file=index.html

@vltansky that last line of code fixed it for me. But i think the lazy loading feature needs more attention, as that somehow seems to me like a hack as it probably should be part of lazy loading, shouldn't it?

Yeah, I think so too.
@nolimits4web take a look on this. Is just adding swiper.update() just before emitting lazyImageReady a good solution?

Solution proposed by @vltansky is not a hack and should be used in this case (when images define slides sizes):

        on: {
          lazyImageReady: (swiper) => {swiper.update()}
        }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

leone510es picture leone510es  路  3Comments

danielcpereira11 picture danielcpereira11  路  4Comments

cristianfierro picture cristianfierro  路  4Comments

RyanGosden picture RyanGosden  路  3Comments

Danetag picture Danetag  路  3Comments