w3c / IntersectionObserver

Intersection Observer
https://www.w3.org/TR/intersection-observer/
Other
3.62k stars 526 forks source link

Allow dynamically changing rootMargin #428

Open zcorpan opened 4 years ago

zcorpan commented 4 years ago

In whatwg/html#5510 I'm trying to specify <img loading=lazy> in terms of IntersectionObserver as per discussion in whatwg/html#5236

The desired behavior for lazy-loading is to dynamically change the rootMargin in response to things like scrolling and network changes. See https://github.com/whatwg/html/issues/5408#issuecomment-623683336

Since IntersectionObserver only allows setting the rootMargin upon initialization, this would require one of

I think the second option seems better, but per the extensible web manifesto we try to have web features be explained by lower-level APIs without having special magic that isn't accessible to web developers.

Are there issues with modifying the rootMargin after initialization?

domfarolino commented 4 years ago

This seems reasonable, but also I don't think it should block https://github.com/whatwg/html/pull/5510

zcorpan commented 4 years ago

Agreed. I think it doesn't need to block fixing https://github.com/whatwg/html/issues/5408 either, we could temporarily violate the extensible web manifesto here. But fixing this first certainly seems nicer to me!

emilio commented 3 years ago

I don't think there'd be an issue allowing this.

zcorpan commented 3 years ago

There will be a TPAC breakout session tomorrow (30 October 14:00–15:00 UTC) to discuss this issue.

https://www.w3.org/2020/10/TPAC/breakout-schedule.html#intersectionobserver

zcorpan commented 3 years ago

The breakout starts in ~20 minutes. Agenda and meeting notes here: https://docs.google.com/document/d/1SXwbMiwOUkLPXSM_klk4q9mFEanbIH8IAgTM80cCMXU/edit?usp=sharing

asakusuma commented 2 years ago

@zcorpan I read the meeting notes, has someone proposed an API here to allow rootMargin mutation?

Another use case here is top navbars that change size.

zcorpan commented 2 years ago

@asakusuma The API we gravitated towards was to allow assigning to rootMargin (and @smfr suggested also allow changing thresholds for symmetry).

In https://github.com/metonym/svelte-intersection-observer/pull/12#issuecomment-805164642 @dysfunc also explains a use case for this feature. The implementation in svelte-intersection-observer validates that there is a web developer need for this feature.

cc @chrishtr

zcorpan commented 2 years ago

PRs: https://github.com/w3c/IntersectionObserver/pull/485 (thresholds), https://github.com/w3c/IntersectionObserver/pull/486 (rootMargin)