Scroll to top on page view #351
Answered
by
daun
thescooble
asked this question in
Help
|
I have a fixed header and when I click on a link that has swup enabled, the animation works fine, but it doesnt scroll to top of the screen for the page I linked to. How do I get it to scroll to the top? |
Answered by
daun
Jun 14, 2022
Replies: 2 comments 2 replies
This comment has been hidden.
This comment has been hidden.
|
Update: swup 4 now comes with scroll support out of the box. The below applies to swup 3: You could either use the swup scroll plugin that will scroll back to the top after each transition, or you could implement a very simple non-animated version of it yourself: swup.on('contentReplaced', () => window.scrollTo(0, 0))Keep in mind this won't handle special cases like browser history visits or links with #hashes. |
2 replies
Answer selected by
daun
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: swup 4 now comes with scroll support out of the box.
The below applies to swup 3:
You could either use the swup scroll plugin that will scroll back to the top after each transition, or you could implement a very simple non-animated version of it yourself:
Keep in mind this won't handle special cases like browser history visits or links with #hashes.