-
Notifications
You must be signed in to change notification settings - Fork 10
Offset with smooth scroll #231
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
Comments
So I have worked around it by giving the element the style rule: |
You can use custom transition with popmotion:
|
@stipsan This is a scenario I'm dealing with – I have a sticky navigation menu header. On click of any menu item, it scrolls to the required element. But because the header sticks, it hides the top of that element a little by virtue of Navigation Menu Header's height. Does it make sense to allow an 'offset' value for top, so that the |
Alright I've had a rethink. I'll make a new major release that lets you map over the coordinates when you provide a custom behavior, applying offsets as needed: // Given this markup:
// <div id="app" style="height: 100vh; overflow: auto;">
// <header style="position: fixed; left: 0; top: 0; right: 0; height: 50px" />
// <div id="hero" />
// <footer id="contact-us" />
// </div>
import scrollIntoView from "smooth-scroll-into-view-if-needed";
const node = document.getElementById("contact-us");
scrollIntoView(node, {
behavior: actions =>
actions.map(action => {
// Ensure the offset is only applied
// to the element that needs it.
if (action.el.matches("#app")) {
// Apply the minimum needed scroll padding
// to stay underneath the sticky header.
action.top = Math.max(50, action.top);
}
return action;
})
}); That'll solve these kind of challenges for now. In the long run I want to extend compute-scroll-into-view itself to support either https://css-tricks.com/almanac/properties/s/scroll-padding/ directly, or provide the API needed to build it in packages like |
Hello, |
I am trying to get a smooth scroll to an element with a sticky navigation bar.
Overriding behavior (to add an offset) also overrides the smooth scroll. Can someone give me some advice on how to make this work?
The text was updated successfully, but these errors were encountered: