rob.m rob.m - 2 months ago 14
jQuery Question

How to scrollTop when html, body is set to height: 100%?

The following won't work unless I remove

height: 100%
from body and html. However, i need that style as I am using it for other elements on the page.

html

<a href="#" id="scrollTop">Back to top</a>


jQuery

$("#scrollTop").on("click",function(e){
e.preventDefault();
$(window).animate({scrollTop: 0}, 'slow');
});


Even tried the following with still negative results

$("#scrollTop").on("click",function(e){
e.preventDefault();
$("body, html").animate({scrollTop: 0}, 'slow');
});


Css

html, body {height:100%; min-height:100%;}

Answer Source

Got the issue, thanks to comments I noticed I had body: overflow-x:hidden which means scrollTop isn't working when we are using overflow on body, html