<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>下拉滚动条滚到底部了吗?</title>
<body>
<div id="div1" style="overflow-y:auto; overflow-x:hidden; height:500px;">
<div style="background-color:#ccc; height:750px;">IE 和 FF 下测试通过</div>
</div>
<script>
HTMLElement.prototype.onScrollToBottom = function (callback) {
var _ele = document.querySelector("#div1");
if(_ele){
this.onscroll = function(e){
if(this.scrollTop + this.offsetHeight >= this.scrollHeight){
if(typeof callback == "function"){
callback();
}
}
return false;
};
}
}
document.querySelector("#div1").onScrollToBottom(function (e) {
alert("dao di le ");
})
</script>
</body>
</html>
本文介绍了一种在网页中检测滚动条是否到达底部的方法,并提供了一个JavaScript实现示例。该方法通过为指定元素添加滚动监听事件,当检测到滚动位置接近元素的底部时触发回调函数。
3013

被折叠的 条评论
为什么被折叠?



