【问题标题】:jQuery - Infinite scrollingjQuery - 无限滚动
【发布时间】:2012-08-17 22:05:04
【问题描述】:

我正在尝试在我的页面上实现无限滚动,但有什么事情搞砸了,而不是在页面底部触发,而是在我滚动回顶部时触发。有谁知道是什么触发了这个?

$(window).scroll(function()
{
    if($(window).scrollTop() == $(document).height() - $(window).height())
    {
        alert("hello");
    }
});

我目前正在使用上面的代码,它在 jsfiddle 中运行得很好。我还尝试了-

if($(window).scrollTop() + $(window).height() == $(document).height())

注意:我正在使用 CodeIgniter(虽然我不确定这会导致问题吗?)

如果您想了解我的意思,您可以查看http://carllawl.kwebserv.info/recent 的测试页面(只需向下滚动然后返回即可了解我的意思)

【问题讨论】:

  • 您能否尝试将其添加到您的脚本中,然后让我们知道它的内容。 chk_val=$(document).height() - $(window).height(); console.log("chk_val=",chk_val);
  • 如果你使用的是firefox,你需要firebug才能看到结果。
  • (使用 chrome)它总是返回 - chk_val= 0
  • 试试这个无限滚动脚本☞github.com/yairEO/infinite

标签: javascript jquery scroll infinite


【解决方案1】:

使用这个

  $(window).scroll(function() {
    if ($(window).scrollTop() <= $(document).height() - $(window).height() && $(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
    yourfunctionhere()
  }
 });

【讨论】:

  • 感谢您的回复,我尝试了您的代码,结果与上述相同!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-01-12
  • 2011-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多