Skip to content

Position Observer #9610

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

Open
arenevier opened this issue Nov 17, 2023 · 4 comments
Open

Position Observer #9610

arenevier opened this issue Nov 17, 2023 · 4 comments

Comments

@arenevier
Copy link

I am currently trying to observe the bounding box of a specific node from an extension. It's easy to observe the size changes with the ResizeObserver. But there is no easy way to observe changes in the node position.

There are imperfect solutions that use IntersectionObserver with rootMargin. See https://samthor.au/2021/observing-dom/ and https://github.com/samthor/viz-observer But there are edge cases where this solution won't work, especially when the element overflows the viewport.

Instead of misusing IntersectionObserver, or resorting to polling, it would be convenient to have an api that reports changes to the position of an element.

@arenevier
Copy link
Author

pinging @samthor who wrote the library I mentioned above.

@Loirooriol
Copy link
Contributor

Position with respect to what? The screen, the containing block, the scrolling container, ...?

@arenevier
Copy link
Author

I was thinking relative to the viewport. This seems the most useful to me. If the user want to know the position relative to an ancestor or any other specific node, they could still use the api, monitor both elements for position changes, and check whether both elements have moved relative to each other.

Another option would be to pass on optional relativeTo parameter, that would default to the viewport if not set.

@ydaniv
Copy link
Contributor

ydaniv commented Nov 23, 2023

I would love to have some sort of PositionObserver to track element's layout-only position changes. So not so much depend on transforms and not really care of relative to viewport, but rather relative to any ancestor containing block.
I've had to write custom logic for this purpose numerous times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants