Home > Article > Web Front-end > javascript quick way to get element position getBoundingClientRect()_javascript tips
It returns an object that contains four attributes: left, right, top, and bottom, which respectively correspond to the distance between the upper left corner and lower right corner of the element relative to the upper left corner of the browser window (viewport).
So, the relative position of the web page element is
var Get the absolute position
var , Opera 9.5 all support this method, but Firefox 2.x, Safari, Chrome, and Konqueror do not support it.