Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any idea how to smooth scroll to elements from hash links? #194

Open
mattsears18 opened this issue Apr 2, 2022 · 1 comment
Open

Any idea how to smooth scroll to elements from hash links? #194

mattsears18 opened this issue Apr 2, 2022 · 1 comment

Comments

@mattsears18
Copy link

I added a unique id to each featured project so that I can use a hash link for each one. https://github.com/mattsears18/mattsears18.com/blob/dab8b93519bfd9f5bf7c5ced3d93a891f7c91c5d/src/components/sections/featured.js#L364

I would like for a link like this: https://mattsears18.com/#nccer-single-sign-on to smooth scroll to the top of the element with that id, but the scrolling is not consistent. Sometimes it scrolls to exactly where I want, sometimes not. I'm not a Gatsby expert, but I think my problem has to do with the way that Gatsby loads the data. I.e. sometimes the element is loaded and can be scrolled to, sometimes not.

Any ideas for how to consistently scroll to an element from a hash link? I'm fine with adding a gatsby plugin if I need to.

@Moamal-2000
Copy link

Have you tried this?

html {
scroll-behavior: smooth;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants