English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
getBoundingClientRect()The method returns the size of the element and its position relative to the viewport.
The returned value is a DOMRect object with eight properties: left, top, right, bottom, x, y, width, and height.
Note:When calculating the boundary rectangle, the scroll amount of the viewport area must be considered. This means that whenever the scroll position changes, the edges (top, left, bottom, and right) of the rectangle will change their values.
element.getBoundingClientRect()
var div = document.getElementById("myDiv"); var rect = div.getBoundingClientRect();Test and See‹/›
All browsers fully support the getBoundingClientRect() method:
Method | |||||
getBoundingClientRect() | Yes | Yes | Yes | Yes | Yes |
Return Value: | The DOMRect object has eight properties: left, top, right, bottom, x, y, width, height |
---|---|
DOM Version: | CSS Object Model (CSSOM) |