javascript - Load more WordPress posts on (infinite) scroll with AJAX -


i'm loading more posts via ajax when user clicks on 'load more' button. code i'm using based on tutorial:

http://www.problogdesign.com/wordpress/load-next-wordpress-posts-with-ajax/

my aim modify code more posts loaded when user scrolls bottom of page. i've tried replacing

$('#pbd-alp-load-posts a').click(function() {  }); 

with this:

$(window).scroll(function(){     if ($(window).scrolltop() == $(document).height() - $(window).height()){      } }); 

when doing that, new posts loaded when user scrolls bottom of browser window second time, next set of posts not loaded page.

using button click approach, new 'load more' button added page next set of posts loaded if user clicks again. how can scroll approach load next set of posts when user scrolls bottom of page again?

in test, instead of using exact equality :

if ($(window).scrolltop() == $(document).height() - $(window).height()) {     ... } 

try using threshold, e.g. :

if ($(window).scrolltop() >= $(document).height() - $(window).height() - 10) {     ... } 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -