Gets position of the element

  You want to get the position of the element:

    We can use getBoundingClientRect () method;

    His return value from, provides a window element to element, not the page

  Understand: getBoundingClientRect used to obtain an element with respect to the collection window. There set top, right, bottom, left and other attributes.

  Usage: let a = obj.getBoundingClientRect () // obj represents the elements we get

         console.log (a) // a is an object that has a position on the above we get the elements who left right top bottom of the property, the above is what we get

  If a page, we can use offsetTop or offsetLeft

Guess you like

Origin www.cnblogs.com/shangjun6/p/11331119.html