
Gabriel F. answered 11/06/19
Tutor
5.0
(85)
Full Stack Software Developer and Mentor
Hi there. I believe you are looking for getBoundingClientRect() method that you can call on DOM element.
From the MOZ docs:
The Element.getBoundingClientRect()
method returns the size of an element and its position relative to the viewport.
The returned value is aDOMRect
object which is the union of the rectangles returned bygetClientRects()
for the element, i.e., the CSS border-boxes associated with the element. The result is the smallest rectangle which contains the entire element, with read-onlyleft
,top
,right
,bottom
,x
,y
,width
, andheight
properties describing the overall border-box in pixels. Properties other thanwidth
andheight
are relative to the top-left of the viewport.
I hope this helps!