1

jQuery provide position function which has top and left value. Either vanilla javascript has getBoundingClientRect()

I don't the difference between them.
When I checked, it's value difference.

getBoundingClientRect() enter image description here

How can I convert jQuery's position to getBoundingClientRect.
As you see, x is 236, but left is 200.

sungyong
  • 2,267
  • 8
  • 38
  • 66

1 Answers1

2

jQuery .position() gets position relative to the parent. From documentation: Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.

getBoundingClientRect - relative to the window. From documentation: The Element.getBoundingClientRect() method returns the size of an element and its position relative to the viewport.

The solution found here: Element's coordinates relative to its parent

flash
  • 32
  • 4