You can count the number of images using Javascript
var offset = $('#gallery').children().length
Then you can make an ajax call for a given route (e.g. / giveImages) that returns a JSON array containing the image URL
$.get('/giveImages?offset=' + offset, function(data) { // data = [ // 'http://foo.com/image/3.jpg', // 'http://foo.com/image/4.jpg', // 'http://foo.com/image/5.jpg' // ] // APPEND STUFF HERE AND justifyGallery })
Full example:
$(window).scroll(function() { if($(window).scrollTop() + $(window).height() == $(document).height()) { var offset = $('#gallery').children().length $.get('/giveImages?offset=' + offset, function(data) { for(var i = 0; i < data.length; i++) { $('#gallery').append( '<a>' + '<img src="' + data[i] + '" />' + '</a>' ) $('#gallery').justifiedGallery('norewind') } }) } }
l0rin
source share