将内容加载为元素滚动到视图中
我在
元素中有一个搜索结果列表,其中包含静态高度和
overflow: auto;
在风格。 我想只加载前x个搜索结果(例如20个),并在用户滚动到包含搜索结果的元素的底部时加载另一个x结果。
任何人都可以向我解释我会怎么做? 我找到了一些示例,但所有这些示例都使用整个文档的滚动值,而不是单个
。 我正在使用jQuery,如果重要的话。
听起来像你想要在接近结束时检测滚动条的位置。 在jquery组上搜索时发现了这一点 。 如果需要,它建议的解决方案添加一些文档:
$.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 });
如果你将div的.top() + .height()
与窗口的.scrollTop + .height
那么你可以告诉你何时在div的底部,然后触发下一个内容加载……
Interesting Posts