I try to make something like infinite scroll, but I don't know how to load content only when the last of div.nextpage is in viewport. I am using viewport JQuery plugin. When its loaded, it should again only work with the last one instance, which is loaded with new content.
In my case the content is loading when the first .nextpage appears in viewport, and then function is unbind.
My code:
function check_nextpage(event) {
$('.nextpage:in-viewport').each(function() {
$(window).unbind('scroll', check_nextpage);
alert('loading content');
});
}
$(document).ready(function() {
$(window).bind('scroll', check_nextpage);
});
The HTML
<content.....>
<a href="../test.html" class="nextpage1">next page</a>
<content.....>
<a href="../test.html" class="nextpage1">next page</a>