如何在JavaScript中获取元素的滚动位置

How can you do that?

你该怎么做?

Once you have the element, you can inspect its scrollLeft and scrollTop properties.

拥有元素后,就可以检查其scrollLeftscrollTop属性。

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 = 

你可能感兴趣的:(js,java,javascript,css,python,ViewUI)