Does anyone know why assigning scrollTop
on the body element no longer works?
eg:
document.body.scrollTop = 200
causes the document not to scroll.
Cause: Chrome finally made scrolling spec conformant in version 61
Solution: Use scrollingElement
Update the example to:
var scrollNode = document.scrollingElement ?
document.scrollingElement : document.body;
scrollNode.scrollTop = 200;
To use Chrome in incognito mode, open the browser and click on the dots at the top right. The third option down should be the option to open a tab in incognito mode. Once you click on it, the incognito tab will open. See if you can scroll while in this mode. If you can, then there’s a good chance that it’s an extension causing the issue.
Step 1: Launch Google Chrome, type chrome://flags to the address bar and press Enter. Step 2: Type smooth scrolling to the search bar and the option should be highlighted. Click the drop-down menu and choose Disabled. Step 3: Restart Chrome and see if the issue of mouse scroll not working in web browser is solved.
To turn off Smooth Scrolling, type chrome://flasgs in the addy bar. To find the option faster, type the word smooth in the search bar, and it should appear automatically. Click on the dropdown menu, where it says default. The disable option should be the last one on the list.
First, open an Incognito window in Chrome (three-dotted menu icon at top right -> New incognito window), then try scrolling to see if the problem persists. If it does, then skip down to the next tip. If the scrolling works, then the issue is probably related to one of your extensions.
The solution described at the end of this question (checking for document.scrollingElement
or falling back to document.body
) won't work on IE, as it doesn't support document.scrollingElement
(docs), and in IE, the scroll element is the HTML element.
I'd therefore suggest that a better solution for this would be something like;
var scrollNode = document.scrollingElement || document.documentElement;
Which should work for all modern browsers.
As a sidenote, it's interesting to consider that the scrollingElement
property seems to have been added for the sole purpose of making it so that we don't need checks/fallbacks for getting the root scrolling element, but due to more browser incompatibilities, we still need a check/fallback in order to use scrollingElement
.
Isn't web dev fun?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With