2012-08-31 34 views
1

我觉得这个问题的答案会变得令人尴尬地变得简单,但是它耗尽了大量时间,我看不到解决方案。我正在制作一个简单的无限滚动功能,并且需要脚本在加载更多内容后识别窗口的新高度。该值始终与第一次加载时间相同。我基于another answer here上的最新代码,但它仍然不起作用。思考?在jQuery AJAX之后获取新窗口高度

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

回答

5

window的高度是浏览器窗口的大小。你想要的高度为bodywindow高度仅在浏览器调整大小时更改。

+1

'的$(document).height()'可以用来 – sabithpocker

+0

获取'window'的高度和'document'不如直接做。每一个速度的改进都是很好的改进;) – ThoKra

+0

我同意你的看法,因为函数绑定到'window scroll event',否则我不认为每个速度改进都很好,并且喜欢遵循'方便超过约定'。 – sabithpocker

1

获取窗口的高度是浏览器窗口的高度。如果您想要文档的高度,则必须使用document而不是windowdocument.height或获取体的高度:jQuery('body').height()

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

这可以称为每当任何调整。

心连心