window.onscroll = function () {
//htmlHeight 是网页的总高度
var htmlHeight = document.body.scrollHeight || document.documentElement.scrollHeight;
//clientHeight是网页在浏览器中的可视高度,
var clientHeight = document.body.clientHeight || document.documentElement.clientHeight;
//scrollTop是浏览器滚动条的top位置,
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
//通过判断滚动条的top位置与可视网页之和与整个网页的高度来返回各项参数
if (scrollTop + clientHeight == htmlHeight) {
alert("到顶了");
}else{
alert("离开顶端");
}
}
可以在if...else... 里面写一些其他事件了