代码之家  ›  专栏  ›  技术社区  ›  Aistina

当元素滚动到视图中时加载内容

  •  4
  • Aistina  · 技术社区  · 16 年前

    <div> overflow: auto;

    <

    2 回复  |  直到 16 年前
        1
  •  4
  •   gnarf    16 年前

    在我看来,你想在滚动条接近末尾时检测其位置。 Found this

    $.fn.isNearTheEnd = function() {
      // remember inside of $.fn.whatever = function() {}
      //   this is the jQuery object the function is called on.
      //   this[0] is DOMElement
        return this[0].scrollTop + this.height() >= this[0].scrollHeight;
    };
    
    // an example.
    $("#content").bind("scroll", function() {
      if ($(this).isNearTheEnd()) // load some content
    });
    
        2
  •  1
  •   nickf    16 年前

    .top() + .height() 到窗户的 .scrollTop + .height 然后,您可以判断何时处于该div的底部,然后触发下一次内容加载。..