Excuse me, how do I get the x, y values in this case?

as shown in the figure, we have a requirement that we will embed a large number of different lengths of DIV2, in DIV1 (similar to a viewport). I need to know the distance from the top edge of the DIV2 to the top of the viewport (x), and the distance from the bottom edge of the DIV2 to the top of the viewport (y)

.

how do I get these two values?

Mar.13,2021

ele.getBoundingClientRect()

// 
// div1position

x: div1.scrollTop - div2.offsetTop
y: div2.offsetHeight - x
Menu