-
Notifications
You must be signed in to change notification settings - Fork 186
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
Is rootMargin working? #330
Comments
Hey So |
Thanks for the fast reply, and fantastic plugin, just substituted my own implementation for this one and couldn't be happier It does work if used for triggering animations, maybe it doesn't work if the browser is capable of lazy loading images and makes this a forced behavior (🤷♂️) |
Thanks! Tested it in Firefox where it also happens, so something's up with it. |
Without images involved, I am now testing 4 divs that are appearing at From previous experiments, it seems that above a certain (negative) value it doesn't get triggered |
Hey @thebuilder, we are also experiencing problems with rootMargin being ignored. Here we are setting rootMargin:Bottom to 702px which should render the next two items on the grid (Red box), but for some reason they are not being detected as InView. The only go InView when the first pixel comes into view. P.S: Negative bottom margin seems to be working ok. |
Digging into this a bit, the problem is that Codesandbox runs inside an iframe - this breaks An issue around this can be found here:
|
Thanks for looking into this @thebuilder! Just for clarification, the build (on the screen above) was not running inside Codesanbox. The strange thing is that negative bottom margin value does seem to work as expected. Let me know if there's anything you'd like me to try. Thanks again and stay safe. |
@thebuilder @kuworking I think I've found the problem (And as I expected, it was at my end). For marginRoot bottom to work the root/target element must be the scrolling container. I realized we were passing null instead of the correct element ref so it was defaulting to using null/document.documentElement as the target. hope this helps those coming from the future. thanks again @thebuilder for the quick response. |
I'll add a note to the FAQ regarding this issue, but otherwise it should be working according to the browser implementation. |
Maybe I'm not understanding well how it should work For instance, I have my landing page (https://github.com/kuworking/kuworking-theme-landing-one) and I have 3 elements that appear at the same Being like this, it works as intended Then, if I write for each element |
The margin is for both top and bottom, so with -500px your viewport needs to be more than 1000px tall for it to trigger. Looks like less in the examples? |
You can use a percentage offset instead. That would make it relative to the viewport size. |
You were right 🙌🙌 Yet it is a bit unintuitive in the sense that a Thanks! (I close the issue then) |
@juanpprieto I seem to be running into the same issue you described. Do you happen to have a code snippet to share? I can't seem to wrap my head around it 🙁 |
Can you share the an example on Codesandbox? |
@thebuilder I went over how I assigned |
Why isn't iframe automatically handled? |
In the recipe for lazy loading images here https://github.com/thebuilder/react-intersection-observer/blob/master/docs/Recipes.md#lazy-image-load I haven't been able to observe any effect related to
rootMargin
This is, images were loading always when barely seen, not before or after
How is this supposed to work?
*In the link example in https://codesandbox.io/embed/lazy-image-load-mjsgc one has to "false"fy the native image loading browser capabilities to test this - in both files (and remove the loading prop)
And the
margin
has also to be corrected torootMargin
(I assume)EDIT: I can see that it is working in other examples where I am triggering animations, but with the one of images It seems to be ignored (?)
The text was updated successfully, but these errors were encountered: