WordPress.org

Forums

Infinite-Scroll
[resolved] How to add a "Back To Top" button ? (4 posts)

  1. corentino
    Member
    Posted 2 years ago #

    Hi !

    I use Infinite Scroll on my website which has now over 250 articles and I would like to add a 'Back To Top' button so my readers won't have to scroll all the way up anymore !

    Can anyone give me some help ?

    http://wordpress.org/extend/plugins/infinite-scroll/

  2. deutschwulf
    Member
    Posted 1 year ago #

    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.)

  3. benarobinson
    Member
    Posted 1 year ago #

  4. corentino
    Member
    Posted 1 year ago #

    Thanks benarobinson !
    It works fine on my site !

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Infinite-Scroll
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic