2016年5月26日
[TOC]
2016年5月26日
jQuery
滚动监听
$(window).scroll(function () {
var $currentWindow = $(window);
//当前窗口的高度
var windowHeight = $currentWindow.height();
console.log("current widow height is " + windowHeight);
//当前滚动条从上往下滚动的距离
var scrollTop = $currentWindow.scrollTop();
console.log("current scrollOffset is " + scrollTop);
//当前文档的高度
var docHeight = $(document).height();
console.log("current docHeight is " + docHeight);
//当 滚动条距底部的距离 + 滚动条滚动的距离 >= 文档的高度 - 窗口的高度
//换句话说:(滚动条滚动的距离 + 窗口的高度 = 文档的高度) 这个是基本的公式
if ((BOTTOM_OFFSET + scrollTop) >= docHeight - windowHeight) {
createListItems();
}
});
window.innerHeight – 浏览器窗口的内部高度,包括滚动条 window.innerWidth – 浏览器窗口的内部宽度,包括滚动条
document.documentElement.clientHeight,根元素html的高度。 document.documentElement.clientWidth,根元素html的宽度。
documentElement 是整个节点树的根节点root,即 标签;
document.body.clientHeight,body元素的高度,可有元素撑起,或者自定义。 document.body.clientWidth,body元素的宽度,可有元素撑起,或者自定义。
clientTop实际上就是border的高度;
Last updated
Was this helpful?