Window scrolls to top onClick
See original GitHub issueI am using links for Previous/Next of PDF pages.
The functionality works great (pages go previous/next as expected). However, my viewport/window scrolls to the top anytime the onClick link is clicked. Would appreciate any advice on how to prevent the page window from scrolling. Thanks!
<a onClick={pageNumber <= 1 ? "event.stopPropagation()" : previousPage}>← Previous</a>
references:
function previousPage() {
changePage(-1);
}
function nextPage() {
changePage(1);
}
Thanks in advance. One of my absolute favorite React projects!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Scroll To Top When DIV Clicked? [closed] - Stack Overflow
We all know that scroll to top with named anchors via HTML is possible but is it possible to scroll to the top...
Read more >How To Create a Scroll Back To Top Button - W3Schools
This example demonstrates how to create a "scroll to top" button that becomes visible when the user starts to scroll the page.
Read more >Scroll to the top of the page using JavaScript/jQuery
A scrollable page can be scrolled to the top using 2 approaches: Method 1: Using window.scrollTo(): The scrollTo() method of the window ......
Read more >Window.scroll() - Web APIs - MDN Web Docs
The Window.scroll() method scrolls the window to a particular place in the document.
Read more >Scroll to the top of the Page in React.js | bobbyhadz
The `scrollTo` method on the `window` object scrolls to a particular set of ... scroll to top on button click */} <button onClick={()...
Read more >Top Related Medium Post
No results found
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
The same thing happened to me. But it only happened when I navigated to a page that hasn’t been displayed before in this session. When changing to a page that was already displayed it did not scroll to the top.
React will scroll viewport to the top when components change dimensions on the page. The solution was to set
width
orheight
on the CSS class of the containerDocument
. (not to be confused with thewidth
orheight
of thePage
)As a heads-up, a combination of CSS and the methods in these threads worked for me: https://github.com/wojtekmaj/react-pdf/issues/418 https://github.com/wojtekmaj/react-pdf/issues/689
Thanks!