Elements position in JavaScript

 

getBoundingClientRect() is a javascript function that returns the position of the element relative to viewport of window.

const position = selector.getBoundingClientRect();

const result = position.top + window.scrollY;

Comments

Popular posts from this blog

spread operator use in reactjs

Break loop once condition match JavaScript