scroll-into-view / scroll-into-view-if-needed

Element.scrollIntoView ponyfills for things like "if-needed" and "smooth"
https://scroll-into-view.dev
MIT License
1.39k stars 76 forks source link

Dealing with a Fixed Navbar #1130

Open dliebner opened 1 year ago

dliebner commented 1 year ago

Let's say we've got a fixed navbar at 60px height. Is there an easy way to pass in / factor in that 60px offset for scroll position calculations? For example, if we try to scroll to the top of an element, with a fixed navbar at the top of the screen, the top part of the element will be covered the navbar.

oneyoung19 commented 10 months ago

I met the same issue,and i didn't find how to settle it in V2.

oneyoung19 commented 10 months ago

OK. I have found this way. We can set scroll-margin-top: 60px in style. This is a new feature in #1197 .But it didn't be written into README yet. It worked on scroll-into-view-if-needed@^3.1.0 or smooth-scroll-into-view-if-needed@^2.0.2 by my test.