Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lazyPreloadPrevNext not working with loop mode #6724

Closed
6 tasks done
rameauv opened this issue Jun 2, 2023 · 0 comments · Fixed by #6726
Closed
6 tasks done

lazyPreloadPrevNext not working with loop mode #6724

rameauv opened this issue Jun 2, 2023 · 0 comments · Fixed by #6726

Comments

@rameauv
Copy link
Contributor

rameauv commented Jun 2, 2023

Check that this is really a bug

  • I confirm

Reproduction link

https://codesandbox.io/p/sandbox/swiper-lazy-load-images-forked-9kxr8y?file=%2Findex.html%3A69%2C76-69%2C80

Bug description

Preconditions:

Initial slide at index 0
lazyPreloadPrevNext > 0
loop = true

After the swiper has finish initializing, the current slide and 2 slides prior to it (since the initial slide index is 0 and the loop mode is enabled, the last 2 slides) should not have loading=lazy, due to lazyPreloadPrevNext:2.

The same code with probably if (realIndex <= activeIndex || realIndex > slideIndexLastInView) instead of if (realIndex !== activeIndex && realIndex > slideIndexLastInView) in case the initial slide index is not 0 should do the trick.

if (swiper.params.rewind) {
for (let i = activeIndex - amount; i <= slideIndexLastInView + amount; i += 1) {
const realIndex = ((i % len) + len) % len;
if (realIndex !== activeIndex && realIndex > slideIndexLastInView) unlazy(swiper, realIndex);
}
} else {

Expected Behavior

The last 2 image should have loading=lazy removed.

Actual Behavior

The last 2 image still have loading=lazy.

Swiper version

9.3.2

Platform/Target and Browser Versions

macOS 13.0.1 (22A400) intel, chrome 113.0.5672.77 (Official Build) (x86_x64)

Validations

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
  • Make sure this is a Swiper issue and not a framework-specific issue

Would you like to open a PR for this bug?

  • I'm willing to open a PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant