swup / scroll-plugin

A swup plugin for smooth scrolling 🏄‍♂️

Home Page:https://swup.js.org/plugins/scroll-plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add `ignore` option

CHE1RON opened this issue · comments

Describe the problem

One cannot opt out of scrolling for individual links in a reliable way.

For example:

  • Upon first use, shouldResetScrollPosition: (link) => !link.matches('.pls-restore') scrolls to the top if the scroll position before was top
  • Even if it 'restores' scroll position, it still scrolls there - I'd like it to just remain at its position.

Describe the proposed solution

It would be great to have data-swup-no-scroll attribute tell the plugin to stay put and not scroll at all (being equivalent to not being used / vanilla swup behavior).

Alternatives considered

See #3 for an alternative (yet overly complicated) implementation.

How important is this feature to you?

  • Nice to have
  • Would make my life a lot easier
  • I cannot use swup without it

Is this about disabling the scroll after navigation or about disabling the animated scroll to an anchor on the same page?

the former!

What's the use case you have in mind? I have a hard time picturing how this could be useful but happy to be convinced of its utility.

I've got multilingual content, so except for text strings, everything's the same. When switching languages, therefore I'd like to retain the scroll position exactly where it is!

Interesting. Seems like a use case that makes sense to support. Feel free to submit a PR if you need this urgently.

I'll see what I can do 😉

Keeping the current scroll position when changing pages would also be a good preparation for swup's eventually coming fragment support.

@CHE1RON I have created PR #52 that could help you to tell scroll plugin to ignore the current visit. Would you like to check it out? This would help us a lot in deciding how the API should look like 🙏

@hirasso Will do! 🙏

I'm closing the issue as this will be supported by swup 4 natively. Stay tuned 🧃

Thanks @daun!