Recognize scroll as an action and observe relative movement #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
scroll
is the action andobserve-scroll
is also a class added to the observed element, listen to the scroll event when one or more "scrollers" is intersecting and track its scroll position relative to where it was originally triggered.Scroll position is added as a custom property:
--distance-from-trigger
As an example, given an element with these classes:
observe-trigger-10-top-scroll
observe-scroll
Once the top of the element intersects the top 10% of the viewport, a
--distance-from-trigger
property will be added to its inline style with the top of the element's current pixel difference from that intersection. As it moves up the viewport, the distance will increase. If it moves down the viewport, the distance will decrease.Once the element is no longer intersecting (distance of < 0), the scroll event will be removed.
That's the best I have at explaining it. 😆
In this branch, you can view
demo/scrollers.html
to see a working iteration.