question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Smooth scrolling by Links

See original GitHub issue

Today, 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:closed
  • Created 6 years ago
  • Comments:23 (7 by maintainers)

github_iconTop GitHub Comments

13reactions
chrisfitkincommented, Mar 21, 2019

@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

11reactions
kripodcommented, Jan 17, 2018

Sure!

if (typeof window !== 'undefined') {
  // Make scroll behavior of internal links smooth
  require('smooth-scroll')('a[href*="#"]');
}

Every a element pointing to an internal link gets smooth scrolling behavior by the code above.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found