Nelfo
Nelfo

Reputation: 3835

Get new window height after jQuery AJAX

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);

Upvotes: 1

Views: 2371

Answers (3)

ShaunOReilly
ShaunOReilly

Reputation: 2206

jQuery(document).ready(function () {

    jQuery(window).resize(function () {
        //alert("window changed");
        resizeBlocks();
    });

});


function resizeBlocks() {
    var clientWidth = jQuery(window).width();
    var clientHeight = jQuery(window).height();
     ......................
    jQuery(".maindatacontent").height(clientHeight);
}

this can be called every time anything resize.

hth

Upvotes: 0

ThoKra
ThoKra

Reputation: 3029

Getting the height of the window is the height of the browser window. If you want the height of the document you have to use document instead of window. document.height or get the height of the body: jQuery('body').height()

Upvotes: 1

James Montagne
James Montagne

Reputation: 78650

The height of the window is the size of the browser window. You want the height of the body. window height only changes when the browser is resized.

Upvotes: 5

Related Questions