I feel like the answer to this question is going to be embarrassingly simple, but it’s eating up a lot of time and I can’t see the solution. I’m making a simple infinite scroll function, and need the script to recognize the new height of the window after loading more content. The value is always the same as first load time. I based this latest code on another answer here, but it’s still not working. Thoughts?
var scrollFunction = function(){
var myTop = jQuery(window).scrollTop();
var myHeight = jQuery(window).height();
if (myTop >= myHeight){
$(window).unbind("scroll");
jQuery.ajax({
type: 'POST',
url: '/ping/thumbs.php',
data: 'foo=bar',
success: function(data){
$(".thumbnails").append(data);
$(window).scroll(scrollFunction);
},
dataType: 'html'
});
};
};
$(window).scroll(scrollFunction);
The height of the
windowis the size of the browser window. You want the height of thebody.windowheight only changes when the browser is resized.