Viewing 3 replies - 1 through 3 (of 3 total)
  • I just hardcoded one into my website. The following snippet slides the button in when you scroll past 800px, and then when the button is clicked it rolls you back up to the top of the page.

    $(document).ready(function(){ 
    
            $(window).scroll(function(){
                if ($(this).scrollTop() > 800) {
        				$('#scrolltotop').stop().animate({ right: '21px' });
    				}
    				else {
        			$('#scrolltotop').stop().animate({ right: '-42px' });
    				}
            }); 
    
            $('#scrolltotop').click(function(){
                $("html, body").animate({ scrollTop: 0 }, 500);
                return false;
            });
    
        });

    All you need to do is include that in the head of your site, and create a <div> with the id of #scrolltotop somewhere on your page (I created a position:fixed element. I recommend you do it that way.)

    Thread Starter corentino

    (@corentino)

    Thanks benarobinson !
    It works fine on my site !

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add a "Back To Top" button ?’ is closed to new replies.