Link to home
Start Free TrialLog in
Avatar of john_yourspace
john_yourspace

asked on

Infinite Scroll Back Button

Hi guys,

I am using infinite scroll like this

 $('#primaryArticleWrapper').infinitescroll({
			  loading: {
						finished: undefined,
						finishedMsg: "<em>Congratulations, you've reached the end of the internet.</em>",
						img: "",
						msg: null,
						msgText: "<em>Loading.</em>",
						selector: null,
						speed: 'fast',
						start: undefined
					},
						 
			navSelector  : "#nav-below",            
						   // selector for the paged navigation (it will be hidden)
			nextSelector : "div .nav-previous a:first",    
						   // selector for the NEXT link (to page 2)
			itemSelector : ".article"          
						   // selector for all items you'll retrieve
		  });
		  
		  // unbind normal behavior. needs to occur after normal infinite scroll setup.
		$(window).unbind('.infscr');
		
		$('#nav-below').hide();
		
		$("a.articleLoadMore").click(function(){
			$('#primaryArticleWrapper').infinitescroll('retrieve');
				return false;
		});
		

Open in new window


Which works perfectly except for the back button, any suggestions this is a wordpress site


thanks,

J
Avatar of eemit
eemit
Flag of Germany image

Try this:
//Click event to scroll to top
$('.scroll-to-top').click(function(){
	$('html, body').animate({scrollTop : 0}, 800);
	return false;
});

Open in new window


Assumes you have this in your template:
<p class="scroll-to-top"><a href="#" >Scroll to top</a></p>

Open in new window

Avatar of john_yourspace
john_yourspace

ASKER

Hi Eemit,

I am not sure how this will work,


The problem is the user scrolls through a number of pages using infinite scroll

so for example he scrolls to page 10 and clicks through to a post , when the back button is used the user is back on page one
Put that in jQuery(document).ready function e.g.:
jQuery(document).ready(function($){
	// put the code I posted in here.
});

Open in new window

but i dont want to scroll to the top?
Oh sorry! my bad!
no problem
Did you saw how Facebook and Google+ handled this issue ?
is it hash bang or?
Are you using the Infinite Scroll plug-in, or something hand-rolled?

http://www.infinite-scroll.com/

What version of WordPress are you using?
using the js from infinite-scroll.com

3.9.1
I wonder if that problem is related to this post:

Screw Hashbangs: Building the Ultimate Infinite Scroll
http://tumbledry.org/2011/05/12/screw_hashbangs_building
Thanks Bob I seen  that, found it tough to understand, we didnt bother implementing it in the end
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial