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

How to use Lazyload with images in scrollable DIV? What is root for? #455

Open
q2apro opened this issue Sep 29, 2023 · 4 comments
Open

How to use Lazyload with images in scrollable DIV? What is root for? #455

q2apro opened this issue Sep 29, 2023 · 4 comments

Comments

@q2apro
Copy link

q2apro commented Sep 29, 2023

I have not a scrollable body, but a scrollable DIV.

Since the scrolling does not happen on the body, the lazyload images are not loaded.

I have seen:

new LazyLoad(images, {
     root: null,
     rootMargin: "0px",
     threshold: 0
});

But in the readme/doc there is not mentioned what root is.

Can I just define the div for root, e.g. root: $('.wrapper'),?

@jadiagaurang
Copy link

Hi @q2apro

The Library is using Intersection Observer API to check whether HTML elements are in the viewport or not!

Per the MDN docs, root is The element used as the viewport for checking the target's visibility. Must be the ancestor of the target. Defaults to the browser viewport if not specified or if null.

@q2apro
Copy link
Author

q2apro commented Oct 8, 2023

In other words, defining a DIV would be valid.

From their website:

let options = {
  root: document.querySelector("#scrollArea"),
  rootMargin: "0px",
  threshold: 1.0,
};

@jadiagaurang
Copy link

Yes, it should be valid! 👌🏼

@q2apro
Copy link
Author

q2apro commented Oct 17, 2023

I have finally tried it, but it does not work. No lazy load trigger when I scroll the DIV up/down.

I have a fixed width and height for the DIV and use CSS overflow-x: auto;.

I had problems with CSS's overflow in the past, so maybe it is also the culprit here.

I could not find issues searching the net, just this here: https://stackoverflow.com/questions/72077165/using-intersectionobserver-instead-of-onscroll-event

Update: I also posted this issue at https://stackoverflow.com/q/77313611/1066234

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

No branches or pull requests

2 participants