function ScollPostion() {
var t, l, w, h;
if (document.documentElement && document.documentElement.scrollTop) {
t = document.documentElement.scrollTop;
// l = document.documentElement.scrollLeft;
// w = document.documentElement.scrollWidth;
// h = document.documentElement.scrollHeight;
} else if (document.body) {
t = document.body.scrollTop;
l = document.body.scrollLeft;
w = document.body.scrollWidth;
h = document.body.scrollHeight;
}
return {
top: t,
left: l,
width: w,
height: h
};
};
window.onscroll = function () {
console.log(ScollPostion());
}
offsetTop
: 距离顶部距离
jquery写法 offset().top