Top view là gì


The Element.getBoundingClientRect() method returns a DOMRect object providing information about the form size of an element & its position relative sầu to the viewport.quý khách sẽ xem: Top view là gì

quý khách hàng vẫn xem: Top view là gìThe returned value is a DOMRect object which is the smallest rectangle which contains the entire element, including its padding and border-width. The left, top, right, bottom, x, y, width, & height properties describe the position & form size of the overall rectangle in pixels. Properties other than width & height are relative sầu to the top-left of the viewport.

Bạn đang xem: Top view là gì


The width & height properties of theDOMRect object returned by the method include the padding & border-width, not only the nội dung width/height. In the standard box Model, this would be equal to lớn thewidth or height property of the element + padding+border-width. But ifbox-sizing: border-box is mix for the element this would be directly equal lớn itswidth or height.

The returned value can be thought of as the union of the rectangles returned by getClientRects() for the element, i.e., the CSS border-boxes associated with the element.

If you need the bounding rectangle relative sầu to lớn the top-left corner of the document, just add the current scrolling position lớn the top và left properties (these can be obtained using window.scrollX và window.scrollY) lớn get a bounding rectangle which is independent from the current scrolling position.

Xem thêm: Các Thuốc Điều Trị Rối Loạn Nhịp Tim Bằng Đông Y: Không Mới Nhưng Hiệu Quả

Cross-browser fallback

Scripts requiring high cross-browser compatibility can use window.pageXOffset and window.pageYOffset instead of window.scrollX and window.scrollY. Scripts without access lớn these properties can use code lượt thích this:

// For scrollX(((t = document.documentElement) || (t = document.toàn thân.parentNode)) &và typeof t.scrollLeft == "number" ? t : document.body).scrollLeft// For scrollY(((t = document.documentElement) || (t = document.body.parentNode)) && typeof t.scrollTop == "number" ? t : document.body).scrollTop



This simple example retrieves the DOMRect object representing the bounding client rect of a simple element, & prints out its properties below it.

div>div>The returned DOMRect object can be modified in modern browsers. This was not true with older versions which effectively returned DOMRectReadOnly. With IE & Edge, not being able to add missing properties to their returned ClientRect, object prevents backfilling x và y.

Due to compatibility problems (see below), it is safest to lớn rely on only properties left, top, right, và bottom.

Xem thêm: Nghĩa Của Từ Equitization Là Gì, Nghĩa Của Từ 'Equitization' Là Gì

rect = elt.getBoundingClientRect()// The result in emptyObj is emptyObj = Object.assign(, rect)emptyObj = ...rect width, ...emptyObj = rectDOMRect properties top,left, right, and bottom are computed using the values of the object"s other properties.