JavaScript中三种绑定事件的方式与去除绑定


原文链接: JavaScript中三种绑定事件的方式与去除绑定

How to develop high performance onScroll event?
javascript - window.onscroll无法刷新scrollTop的值? - SegmentFault 思否

return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;

scrolltop = (((t = document.documentElement) || (t = document.body.parentNode)) typeof t.scrollTop == ‘number’ ? t : document.body).scrollTop

var Math = window.Math;
Math.max(window.pageYOffset, document.documentElement.scrollTop, document.body.scrollTop)

加载自动向下滚动

 window.onload = function () {
                window.scroll(0, 100);
            }
            
window.onscroll = function () {
    var scrollTop = window.pageYOffset || document.documentElement.scrollTop ||document.body.scrollTop;
    console.log(scrollTop);
}
if (document.compatMode == \"BackCompat\") {
cWidth = document.body.clientWidth;
cHeight = document.body.clientHeight;
sWidth = document.body.scrollWidth;
sHeight = document.body.scrollHeight;
sLeft = document.body.scrollLeft;
sTop = document.body.scrollTop;
}
else { //document.compatMode == \"CSS1Compat\"
cWidth = document.documentElement.clientWidth;
cHeight = document.documentElement.clientHeight;
sWidth = document.documentElement.scrollWidth;
sHeight = document.documentElement.scrollHeight;
sLeft = document.documentElement.scrollLeft == 0 ? document.body.scrollLeft : document.documentElement.scrollLeft;
sTop = document.documentElement.scrollTop == 0 ? document.body.scrollTop : document.documentElement.scrollTop;
}
`