react-scroll icon indicating copy to clipboard operation
react-scroll copied to clipboard

First click on link scrolls to incorrect position

Open dalalRohit opened this issue 4 years ago • 4 comments

I have a navbar with 4 links with their scroll-to-component (to) and all other props defined. When I click any of the link for first-time after a page refresh, it takes me some few pixels down than the actual component. I have also set up offset for each link, still for the first time when I click on any link, it takes me to the incorrect position. After the first click, it behaves as expected and scrolls to perfect component. Why is it for only the first link click? Not getting any clue.

Any help will be highly appreciated. Thank you ;)

dalalRohit avatar May 08 '20 06:05 dalalRohit

I experienced the same behavior, but it turned out that the first child of the target scroll-to-component had a top margin. Removing this top margin solved the problem for me.

ckeeney avatar May 08 '20 23:05 ckeeney

I experienced the same behavior, but it turned out that the first child of the target scroll-to-component had a top margin. Removing this top margin solved the problem for me.

I'm still not able to solve this. I don't have any margin-top on the target element. Still, it takes me a few pixels down the intended position. Not sure why this is the case

dalalRohit avatar May 23 '20 17:05 dalalRohit

I am having similar problem also but i am getting it on every click . I don't know why.

sharifhimu avatar Jul 07 '20 06:07 sharifhimu

I had the same issue and it turned out that my wrapper element (wrapping the target element) had negative top margin which effected the scrolling behavior. After I removed the negative top margin it worked.

slemke avatar Jul 20 '20 01:07 slemke