滚动到页面底部并无限滚动

时间:2011-10-29 10:12:38

标签: javascript jquery scroll

我正在尝试创建一个无限滚动的网页。现在问题是,它现在似乎不起作用:

    window.scroll(function() {
    alert('Scrolling');
    if ($(this)[0].scrollHeight - $(this).scrollTop() == $(this).outerHeight()) {
            alert('Reached the bottom');
    }
    });

我对jquery很新,即使它本质上是javascript(对吧?)反正,我做错了什么?我也尝试过document.scroll和document.body.scroll

4 个答案:

答案 0 :(得分:3)

试试这个:

 if ($(this).scrollTop() ==  $(document).height() - $(window).height()) {
            alert('Reached the bottom');
    }

我对它进行了调整并且有效:http://jsfiddle.net/wcKVK/1/

答案 1 :(得分:1)

那里至少有一个错误。尝试:

 $(window).scroll(function() {
    alert('Scrolling');
    if ($(this)[0].scrollHeight - $(this).scrollTop() == $(this).outerHeight()) {
            alert('Reached the bottom');
    }
    });

答案 2 :(得分:1)

我认为这是你想要实现的目标:

$(window).scroll(function() {
  if ($('body').scrollTop() + $(window).height() == $('body').outerHeight()) {
    alert('Reached the bottom');
  }
});

答案 3 :(得分:-1)

(function ($) {
    $(window).scroll(function () {
        if ($(this).scrollTop() == $(document).height() - $(window).height()) {
            alert('bottom');
        }
    });
}(jQuery));

对我有用。

相关问题