swup / scroll-plugin

A swup plugin for smooth scrollingย ๐Ÿ„โ€โ™‚๏ธ
https://swup.js.org/plugins/scroll-plugin
MIT License
3 stars 8 forks source link

Add option to specify header offset #5

Closed daun closed 3 years ago

daun commented 4 years ago

Add an option to offset the final scroll position by a specific amount. Can be either a static number or a function that calculates the offset on demand before each scroll.

new SwupScrollPlugin({
    // Number: fixed offset in px
    offset: 30,
    // Function: calculate offset before scrolling
    offset: () => document.querySelector('#header').offsetHeight
});
afmarchetti commented 4 years ago

cool stuff!

gmrchk commented 3 years ago

I was always against this option and was in favor of this approach instead, but over time I see, I'm the only one that thinks that. ๐Ÿ˜… Let's merge it once we're done with the comments above. โ˜๏ธ

daun commented 3 years ago

I was always against this option and was in favor of this approach instead, but over time I see, I'm the only one that thinks that. ๐Ÿ˜…

The CSS solution is definitely more elegant, but you have to remember to do that for every possible anchor on your page...

daun commented 3 years ago

I added the proposed changes and documentation on the element argument.

gmrchk commented 3 years ago

Published 1.1.0. Really nice work. ๐Ÿ‘ I'll update the docs site.