window scroll事件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// 滚动条滑动到底部,开始加载
$(window).on('scroll', function(){
var docHeight = Drupal.verycdn_tools.getDocHeight();
var scrollTop = $(this).scrollTop();
var winHeight = $(this).height();
if(scrollTop >= docHeight - winHeight) {
//TODO
}
});

Drupal.verycdn_tools.getDocHeight = function () {
var doc = document;
return Math.max(
Math.max(doc.body.scrollHeight, doc.documentElement.scrollHeight),
Math.max(doc.body.offsetHeight, doc.documentElement.offsetHeight),
Math.max(doc.body.clientHeight, doc.documentElement.clientHeight)
);
}