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

support dynamically changing the rootMargin #12

Merged
merged 2 commits into from
Apr 23, 2021

Conversation

dysfunc
Copy link
Contributor

@dysfunc dysfunc commented Mar 23, 2021

Allows for updating rootMargin after init to accommodate scrolling, zooming, network, etc. changes.

There's a discussion happening around this currently with the W3C IO Spec. It sounds like it will eventually be supported, but is not something currently provided.

w3c/IntersectionObserver#428

Thoughts?

@metonym
Copy link
Owner

metonym commented Mar 23, 2021

What's your use case? Can you provide some code?

@dysfunc
Copy link
Contributor Author

dysfunc commented Mar 23, 2021

Scenario:

  • I have a container element that has N child nodes.
  • Each child node is tracked using IO to determine viewability.
  • The child elements also dynamically change scale on zooming/pinch-zoom gesture occurs using CSS transforms. When scaled down past a certain threshold the rootMargin needs to be adjusted to accurately detect the correct element.

@metonym
Copy link
Owner

metonym commented Mar 23, 2021

And why not use the #key API to recreate the component if the root margin changes?

@dysfunc
Copy link
Contributor Author

dysfunc commented Mar 23, 2021

Using #key satisfies simple cases where you can afford to destroy and recreate static elements. Applying #key to anything dynamic will reset when rootMargin changes.

@metonym metonym self-requested a review April 17, 2021 19:04
@metonym
Copy link
Owner

metonym commented Apr 17, 2021

I'll take another look at this – I agree that updating the root margin can be a common enough use case.

Copy link
Owner

@metonym metonym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for keeping this up to date. Tested locally and it works great.

@metonym metonym merged commit 76b5a4a into metonym:master Apr 23, 2021
@metonym
Copy link
Owner

metonym commented Apr 23, 2021

Published to NPM in version 0.7.0

@ysfcbn
Copy link

ysfcbn commented Jul 20, 2022

I need to use it with JavaScript. can you help me please for convert this code JS syntax?

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 this pull request may close these issues.

3 participants