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

浏览器兼容性