I use this https://infinite-scroll.com
For normal scrolling through pages it works great out of the box.
I have a problem though, I have a regular navigation at the top of my page. What I would like to accomplish is this:
Visitor enters site. page-1 is loaded Visitor clicks Page-3 in my navigation, I would like page-2 to load and then page-3 and automatically scroll down to page-3
each page starts with a div with and ID e.g.
function checkAnchor( anchor ) {
if ( $( anchor ).length ) {
return true;
} else {
$( '.article-feed' ).infiniteScroll( 'loadNextPage' );
checkAnchor( anchor );
}
}
$( document ).on( 'click', 'a[href^="#"]', function ( event ) {
event.preventDefault();
anchor = $.attr( this, 'href' );
while ( checkAnchor( anchor ) == false ) {
$( '.article-feed' ).infiniteScroll( 'loadNextPage' );
}
$( 'html, body' ).animate( {
scrollTop: $( $.attr( this, 'href' ) ).offset().top
}, 700 );
} );
I have tried many different things to accomplish this but I cant seem to get it to work. The next page loads but i have to click to link until page-3 is finally loaded. Any help is welcome
while ( checkAnchor( anchor ) == false )I don't use infinate-scroll, but this piece of code issync, the loading of the page is going to beasync, so you can't do that. Ideally, Infinate-scroll could do with a pageLoaded callback you could use, but if your pages have specific tags / ids then you could wait using a setInterval callback.