JS获取滚动条的滚动距离

function getScrollOffset() {
 if (window.pageXOffset) {
 return {
 x: window.pageXOffset,
 y: window.pageYOffset
 }
 } else {
 return {
 x: document.body.scrollLeft + document.documentElement.scrollLeft,
 y: document.body.scrollTop + document.documentElement.scrollTop
 }
 }
}

 

posted @ 2022-01-02 01:25  程序员小明1024  阅读(2754)  评论(0编辑  收藏  举报