LayoutShift: value 屬性
LayoutShift 介面的只讀屬性 value 返回佈局移動得分,該得分計算為影響分數(視口移動的部分所佔比例)乘以距離分數(移動距離佔視口的比例)。
值
一個介於 0.0 和 1.0 之間的數字,表示佈局移動得分。
其計算方法是:影響分數(視口移動的部分所佔比例)乘以距離分數(移動距離佔視口的比例)。
layout shift score = impact fraction * distance fraction
有關更多詳細資訊,請參閱 web.dev 上的 佈局移動得分。
示例
記錄條目的佈局移動得分
以下示例顯示瞭如何使用 value 屬性來記錄佈局移動得分。
js
const observer = new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
// Count layout shifts without recent user input only
if (!entry.hadRecentInput) {
console.log("Entry's layout shift score:", entry.value);
}
}
});
observer.observe({ type: "layout-shift", buffered: true });
規範
| 規範 |
|---|
| 佈局不穩定 API # dom-layoutshift-value |
瀏覽器相容性
載入中…