Javascript 当滚动条距离窗口底部200px时加载AJAX页面,窗口大小可能会有所不同

Javascript 当滚动条距离窗口底部200px时加载AJAX页面,窗口大小可能会有所不同,javascript,ajax,jquery-ui,jquery,Javascript,Ajax,Jquery Ui,Jquery,到目前为止,我已经尝试过这种情况 'if ($(window).scrollTop() == $(document).height() - $(window).height())' 有人能帮我找到解决办法吗 $(window).on('scroll', function() { if (($(this).scrollTop() + $(this).height()) - $(document).outerHeight(true) > (-200)) {...} }); 试试这个

到目前为止,我已经尝试过这种情况

'if ($(window).scrollTop() == $(document).height() - $(window).height())'
有人能帮我找到解决办法吗

$(window).on('scroll', function() {
    if (($(this).scrollTop() + $(this).height()) - $(document).outerHeight(true) > (-200)) {...}
});
试试这个:

$(function () {
    $(window).on('scroll', function () {
        if ($(window).scrollTop() + $(window).height() >= $(document).height() - 200) {
            //initate ajax here
        }
    });
});

为什么它也有一些缺陷buddyNope,它根本不是缺陷,你可能只是用错了。