Skip to content

fix: respect scroll-margin and scroll-padding in scrollTo#507

Open
clementroche wants to merge 4 commits intomainfrom
scroll-padding
Open

fix: respect scroll-margin and scroll-padding in scrollTo#507
clementroche wants to merge 4 commits intomainfrom
scroll-padding

Conversation

@clementroche
Copy link
Member

Summary

  • Account for scroll-margin on target elements and scroll-padding on the scroll container when calculating scroll positions in scrollTo()
  • Aligns Lenis behavior with native Element.scrollIntoView()
  • Uses getComputedStyle() only when scrolling to a DOM element (no perf impact on coordinate-based scrolls)

Fixes #503
Fixes #196

Test plan

  • Open playground scroll-margin example
  • Verify elements with scroll-margin land at the correct offset
  • Verify containers with scroll-padding are respected
  • Verify initial hash navigation respects offsets
  • Verify no regression on scrollTo() with numeric targets

Copy link
Contributor

@feledori feledori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reading from scrollmargins and paddings should not trigger reflows so this looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants