获取滚动高度

获取滚动高度 #

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
function getPageScrollY() {
    let yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    } else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
    }
    return yScroll;
};

也可以window.scrollY