此代码已测试并验证有效。当您滚动div时,代码通过比较滚动条高度和滚动条位置来检查滚动条是否到达底部。如果是这样,它将调用一个获取更多内容并将其附加到div的方法。
享受吧!
科比
$(文档).ready(函数(){$(“div”).sroll(函数(){var$this=$(this);var height=this.scrollHeight-$this.height();//获得跳水高度var scroll=$this.scrollTop();//获取垂直滚动位置var isScrolledToEnd=(滚动>=高度);$(“.croll-pos”).text(滚动);$(“.croll-height”).text(高度);if(滚动到结束){var additionalContent=获取更多内容();//获取其他内容$this.append(附加内容);//附加附加内容}});});
根据您的评论,以下是正在运行的整个HTML页面源代码(在IE 9下测试):
**请确保您正在引用jquery库**
<html xmlns=“http://www.w3.org/1999/xhtml"><头部><title>测试图像<script src=“assets/js/jquery.js”type=“text/javascript”></script><script type=“text/javascript”>$(文档).ready(函数(){$(“div”).sroll(函数(){var$this=$(this);var height=this.scrollHeight-$this.height();//获得跳水高度var scroll=$this.scrollTop();//获取垂直滚动位置var isScrolledToEnd=(滚动>=高度);$(“.croll-pos”).text(滚动);$(“.croll-height”).text(高度);if(滚动到结束){var additionalContent=获取更多内容();//获取其他内容$this.append(additionalContent);//附加附加内容}});});函数GetMoreContent(){return“这是div内容;}</script></头><body><div style=“溢出:滚动;高度:150px;边框:1px实心红色;”><p>这是div内容</p><p>这是div内容</p><p>这是div内容</p><p>这是div内容</p><p>这是div内容</p><p>这是div内容</p></div>滚动高度:<span class=“Scroll-Height”></span><br/>滚动位置:<span class=“Scroll-pos”></span></body></html>