獲取瀏覽器滾動距離

/**
   * 獲取瀏覽器滾動距離
  */
   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
             }
         }
     }     console.log(getScrollOffset());
相關文章
相關標籤/搜索