darkroomengineering / lenis

How smooth scroll should be
https://lenis.darkroom.engineering
MIT License
8.63k stars 372 forks source link

`scroll-margin` / `scroll-padding` are not taken into account #196

Open Voltra opened 1 year ago

Voltra commented 1 year ago

Describe the bug When using Lenis#scrollTo to scroll to an element, the scroll-margin and/or scroll-padding properties are ignored, thus making it scroll beyond the desired point.

To Reproduce This minimal codepen.

Desired Behavior

scroll-margin and scroll-padding should be used when determining where to stop scrolling (like the native Element#scrollIntoView does).

clementroche commented 1 year ago

This is a good idea however it has an huge impact on performance since it requires getComputedStyle(). For that reason i don't want to include it by default in the package but you can do it by yourself using scrollTo(value,{offset: scrollMarginValue}).

Voltra commented 1 year ago

Gotcha, maybe in the future we could have a flag in the constructor to enable automating this?