-
Notifications
You must be signed in to change notification settings - Fork 62
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
How to use offset #25
Comments
Agree with @mpetricek. Would be nice to have an example of using scroll with offset in documentation. For now, You can use custom scroll function:
|
You're missing a close brace after scrollWithOffset |
bit hacky but it works as a one-liner. (64 being the height of my header / the amount I want offset). |
Yeap this actually works, but if you want to put some animation on scrolling, you dont have it |
This functions is working for me:
|
I prefer @Vidit92's solution because it preserves the smooth scrolling. Just a note, you can simply use |
this does not work for me |
thank you all I was very stressed trying to figure this out for a client was losing my mind. much appreciated. |
I was in the same boat until I ran "npm run build" and restarted localhost. |
Added a section to the readme with a link to this thread. This seems to be a common question, so if anyone would like to create a formal doc that explains how to scroll with offset, PRs are welcome. |
There's a typo: scrollWidthOffset vs scrollWithOffset . Works if you fix that. |
I'm using scrolling of in-page links with this offset. The question is, if you jump to the link destination of the in-page link with a hash Page A
Page B
Best Regard. |
@yuya-tani the best way is to account for the size of the image on the page before the image is loaded (use css to specify the space that the image will take up). Comments in #84 may help. |
Thank you for your quick reply. Certainly, if the image is fixed, it is better to secure the height first in the component where the image is displayed. It's a good idea. I saw #84 for reference, but if the height of the image changes dynamically |
const scrollWithOffset = (el) => window.scrollTo({ top: el.getBoundingClientRect().top + window.pageYOffset - 100, behavior: 'smooth' }); <HashLink smooth scroll={el => scrollWithOffset(el)} to="/new/legal-compliance#TermsConditionsSec" className="nav-link active" aria-current="page" >
Terms & Conditions
</HashLink> |
The above solutions work, but when I replace |
Hi,
I'm trying to find out how to use offset function. Can you please write me a better explanation or perhaps better documentation?
Thank you!
The text was updated successfully, but these errors were encountered: