auto animated scroll down using jQuery

30,623

Solution 1

I think you need to calculate body height and pass that to the scrollTop parameter in the animate

$('body,html').animate({ scrollTop: $('body').height() }, 800);

[Check here the working demo] // Link has stopped working

Solution 2

$('#back-bottom a').click(function () {
                $('body,html').animate({ scrollTop: $('body').height() }, 500);
                return false;
            });

i think it will work for you

Share:
30,623
user1656139
Author by

user1656139

Updated on January 25, 2020

Comments

  • user1656139
    user1656139 over 4 years

    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>
    
    • Sibu
      Sibu over 11 years
      can you show your html markup too
    • Asciiom
      Asciiom over 11 years
      Create a fiddle for this please so people can see what's going wrong exactly. It's hard to guess
  • user1656139
    user1656139 over 11 years
    Thanks I really appreciate it and please do give me that demo link
  • Michael Peterson
    Michael Peterson over 11 years
    Should work for scrolling to the bottom, but there was also an error in the code for showing the button when not at the bottom.
  • user1656139
    user1656139 over 11 years
    thanks soo much it works great howerever 2 problems 1 it does not scroll smooth and 2 it does not fade out please tell me how to achive that thanks
  • Anudeep GI
    Anudeep GI over 11 years
    first think u needed is smooth scroll for that 500 increase to 1000 or how much u needed depending upon that
  • Anudeep GI
    Anudeep GI over 11 years
    for fade out use this code $('#back-bottom a').fadeOut('slow'); (after this code use fade out code $('body,html').animate({ scrollTop: $('body').height() }, 500); )