How to get scrollbar position with Javascript?

前端 未结 9 2243
自闭症患者
自闭症患者 2020-11-22 11:23

I\'m trying to detect the position of the browser\'s scrollbar with JavaScript to decide where in the page the current view is. My guess is that I have to detect where the t

9条回答
  •  渐次进展
    2020-11-22 11:50

    You can use element.scrollTop and element.scrollLeft to get the vertical and horizontal offset, respectively, that has been scrolled. element can be document.body if you care about the whole page. You can compare it to element.offsetHeight and element.offsetWidth (again, element may be the body) if you need percentages.

提交回复
热议问题