LayoutShiftAttribution: previousRect 屬性

可用性有限

此特性不是基線特性,因為它在一些最廣泛使用的瀏覽器中不起作用。

實驗性: 這是一項實驗性技術
在生產中使用此技術之前,請仔細檢查瀏覽器相容性表格

previousRectLayoutShiftAttribution 介面的一個只讀屬性,它返回一個 DOMRectReadOnly 物件,表示元素在佈局偏移發生前的**位置**。

一個 DOMRectReadOnly 物件。

示例

以下示例會將 LayoutShift.sources 中第一個專案的 previousRect 列印到控制檯。

js
new PerformanceObserver((list) => {
  for (const { sources } of list.getEntries()) {
    if (sources) {
      console.log(sources[0].previousRect);
    }
  }
}).observe({ type: "layout-shift", buffered: true });

規範

規範
佈局不穩定 API
# dom-layoutshiftattribution-previousrect

瀏覽器相容性