How can you do that?
你该怎么做?
Once you have the element, you can inspect its scrollLeft
and scrollTop
properties.
拥有元素后,就可以检查其scrollLeft
和scrollTop
属性。
The 0, 0
position is always found in the top left corner, so any scrolling is relative to that.
总是在左上角找到0, 0
位置,因此任何滚动都与之相对。
Example:
例:
const container = document.querySelector('. container')
container.scrollTop
container.scrollLeft
Those properties are read/write, so you can also set the scroll position:
这些属性是可读写的,因此您还可以设置滚动位置:
const container = document.querySelector('. container')
container.scrollTop = 1000
container.scrollLeft = 1000
翻译自: https://flaviocopes.com/how-to-get-scroll-position-element/