I got a solution from stackoverflow to scroll to the top of the page like
$('html, body').animate({scrollTop: $("#page").offset().top}, 2000);
But I am not sure why to use 'html, body' for scrollTop instead of just 'html' ?
scrollTop is deprecated in strict mode.
scrollTop property gets or sets the number of pixels that an element's content is scrolled vertically. An element's scrollTop value is a measurement of the distance from the element's top to its topmost visible content. When an element's content does not generate a vertical scrollbar, then its scrollTop value is 0 .
.scrollTop()Returns: Number Description: Get the current vertical position of the scroll bar for the first element in the set of matched elements or set the vertical position of the scroll bar for every matched element.
Some browsers apply the "overall" scroll to document.documentElement
(the <html>
element) and others to document.body
(the <body>
element). For compatibility with both, you have to apply the scrolling to both.
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