Repository navigation
feat: support arbitrary threshold values via intersect-[value] modifier - #16
Closed
andreas-fahrecker wants to merge 2 commits into
Closed
andreas-fahrecker wants to merge 2 commits into
andreas-fahrecker wants to merge 2 commits into
Conversation
…rbitrary-value convention
Owner
|
First of all, thanks for the idea and your contribution! I'm going to close this PR, but the feature itself made it in. I've implemented the modifier myself, with a few things that differ from your original version:
All of this will be in the upcoming 3.0 release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds support for arbitrary intersection thresholds using Tailwind's
bracket syntax, e.g.
intersect-[0.3], alongside the existingintersect-halfandintersect-fullmodifiers.Motivation
Currently the only threshold options are
intersect-half(0.5) andintersect-full(0.99). Any other threshold requires forking theObserver script. This PR lets users pick any threshold between 0 and 1
without touching JS, the same way Tailwind already handles arbitrary
values elsewhere (
opacity-[0.3],top-[117px], etc.).Changes
_getThreshold()now falls back to parsingintersect-[<value>]off the element's class list when no namedthreshold (
intersect-half/intersect-full) matches. Parsedvalues are clamped to
[0, 1].section, next to
intersect-half/intersect-full.Backwards compatibility
Fully additive —
intersect-half,intersect-full, and the defaultObserver.start()behavior are unchanged. No breaking changes.Testing
Tested locally in an Astro project (not the repo's demo page):
intersect-[0.3],intersect-[0.75],intersect-[1]trigger atthe expected scroll positions.
intersect-[1.5]) clamp to1instead ofsilently failing.
intersect-half/intersect-fullclasses still resolvecorrectly (named thresholds take priority over parsing).
Open question for maintainer
Happy to rename
intersect-[value]to something more explicit (e.g.intersect-threshold-[value]) if you'd prefer it to be moreexplicitly named. Wanted to keep the first pass minimal and get your
take before bikeshedding it further.