Smooth scrolling by Links
See original GitHub issueToday, I tried my best to implement anchor-based smooth scrolling for a single-page application, but failed after multiple tries. I wanted to add smooth scrolling for my Link
elements (from gatsby-link) using the following libraries:
I also tried some React-targeted alternatives, but they didn’t work either. Unfortunately, I could not find an answer to this problem, so I would highly appreciate any kind of assistance.
Issue Analytics
- State:
- Created 6 years ago
- Comments:23 (7 by maintainers)
Top Results From Across the Web
Smooth Scrolling | CSS-Tricks
I have been experimenting with the script and it is working well, mostly. When I create a “back to top” link referring to...
Read more >Smooth scrolling when clicking an anchor link - Stack Overflow
You can use window.scroll() with behavior: smooth and top set to the anchor tag's offset top which ensures that the anchor tag will...
Read more >How to Create Smooth Scrolling When Clicking an Anchor Link
Smooth scrolling allows jumping between page sections in just one click without manually scrolling up or down. To have this feature on your...
Read more >How To Create a Smooth Scrolling Effect - W3Schools
Learn how to create a smooth scrolling effect with CSS. Smooth Scrolling. Section 1. Click on the link to see the "smooth" scrolling...
Read more >How to create a smooth scroll effect for same-page navigation ...
How to create same-page navigation links with a smooth scroll action ... For this part, it's truly pretty simple. Add a Code Block...
Read more >Top Related Medium Post
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kripod thanks your code snippet worked great for my site!
I used it to write a small demo with instructions in case it helps anyone in the future.
demo code: https://github.com/chrisfitkin/gatsby-smooth-scroll-demo/ instructions: https://medium.com/@chrisfitkin/how-to-smooth-scroll-links-in-gatsby-3dc445299558
Sure!
Every
a
element pointing to an internal link gets smooth scrolling behavior by the code above.