Skip to content
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

feat: mirror html elements with the :root's scroll position #18

Merged
merged 21 commits into from
Dec 26, 2023

Conversation

hirasso
Copy link
Owner

@hirasso hirasso commented Dec 26, 2023

Description

Adds experimental support for mirroring the scroll position between the root and HTML elements.

API

new ScrollMirror(document.querySelectorAll(':root, .scroller1, .scroller2'));

This is being achieved like this: If the library detects either html or body elements in the provided elements option, it will normalize the behavior like this:

  1. Add a scroll event handler to the window
  2. Measure the offsets and dimensions from the document.documentElement

Notes

  • In my manual tests, this is working fine on desktop (Chromium, FF, Safari).
  • on iOS Safari, momentum scrolling is sometimes becoming a bit flaky

Demo

https://deploy-preview-18--scrollmirror.netlify.app/root/

TODO

  • Make sure only one of :root, html and body makes it into the final elements array

Checks

  • The PR is submitted to the main branch
  • The code was formatted before pushing (npm run format)
  • All tests are passing (npm run test)
  • New or updated tests are included
  • The documentation was updated as required

Additional information

Copy link

netlify bot commented Dec 26, 2023

Deploy Preview for scrollmirror ready!

Name Link
🔨 Latest commit 161d596
🔍 Latest deploy log https://app.netlify.com/sites/scrollmirror/deploys/658b4a3e58e6f10008c535c2
😎 Deploy Preview https://deploy-preview-18--scrollmirror.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@hirasso hirasso changed the title feat: mirror html elements with the root scroll position feat: mirror html elements with the :root's scroll position Dec 26, 2023
@hirasso hirasso merged commit 208bd24 into main Dec 26, 2023
5 checks passed
@hirasso hirasso deleted the feat/document-mirroring branch December 26, 2023 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant