Skip to content

Conversation

believer
Copy link

@believer believer commented Jun 5, 2024

Description

Add support for rootMargin in intersect triggers. This allows us to extend the size of the intersect area. I've selected to separate multiple values using underscores, similar to how Tailwind solves it.

Corresponding issue: #1349

Testing

I've tested it locally using one of my own projects. I didn't find any tests for the intersect modifiers, so I couldn't find anything to base new tests on.

Checklist

  • I have read the contribution guidelines
  • I have targeted this PR against the correct branch (master for website changes, dev for
    source changes)
  • This is either a bugfix, a documentation update, or a new feature that has been explicitly
    approved via an issue
  • I ran the test suite locally (npm run test) and verified that it succeeded

@Telroshan Telroshan added the enhancement New feature or request label Jun 6, 2024
@1cg
Copy link
Contributor

1cg commented Jun 27, 2024

i like everything about this except the underscores. What if we consumed until EOF or the next token followed by a colon? (this may be a horrible idea idk)

@believer
Copy link
Author

I wasn't too excited about the underscores either, but I didn't have a better idea at the time. Two other options could be:

  • /,|(root)|(threshold)/ to match comma or one of the other two intersect options
  • /[,rt]/ for comma and the starting character of the options

I think the first option is easier to understand though

@believer
Copy link
Author

believer commented Sep 9, 2024

@1cg any thoughts on the updated parsing proposal above?

@believer
Copy link
Author

I came to need this again, so I updated the API without the need for underscores. Now it works with all these variations:

  • intersect rootMargin:10%
  • intersect rootMargin:10px 20px 30px 40px
  • intersect rootMargin:10px 10px threshold:0.1
  • intersect rootMargin:10px 10px threshold:0.1 root:#test

@gustafnk
Copy link

gustafnk commented May 1, 2025

Hi! Given there might be many elements with the need for lazy loading scroll with the same margin value, it would be nice to support setting a default value for all elements instead of specifying it for each element (not sure exactly how though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants