I am trying to make an animated scroll to a bottom button using jQuery that fades out when the page is located at the bottom. I have found this code on the internet and modified it, but I could not get it work.
<script>
//to bottom
$(document).ready(function(){
// hide #back-top first
$("#back-bottom").show();
// fade in #back-top
$(function () {
$(window).scroll(function () {
if ($(this).scrollTop() 1) {
$('#back-bottom').hide();
} else {
$('#back-bottom').show();
}
});
// scroll body to 0px on click
$('#back-bottom a').click(function () {
$('body,html').animate({ scrollTop: 0 }, 800);
return false;
});
});
});
</script>
I think you need to calculate body height and pass that to the scrollTop parameter in the animate
[Check here the working demo]// Link has stopped working