Scroll to top on page view #351
-
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? |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
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.