Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. LayoutShiftAttribution

LayoutShiftAttribution

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.

TheLayoutShiftAttribution interface provides debugging information about elements which have shifted.

Instances ofLayoutShiftAttribution are returned in an array by callingLayoutShift.sources.

Instance properties

LayoutShiftAttribution.nodeRead onlyExperimental

Returns the element that has shifted (null if it has been removed).

LayoutShiftAttribution.previousRectRead onlyExperimental

Returns aDOMRectReadOnly object representing the position of the element before the shift.

LayoutShiftAttribution.currentRectRead onlyExperimental

Returns aDOMRectReadOnly object representing the position of the element after the shift.

Instance methods

LayoutShiftAttribution.toJSON()Experimental

Returns a JSON representation of theLayoutShiftAttribution object.

Examples

The following example finds the element with the highest layout shift score, and returns the element in that entry with the largest size prior to the shift (previousRect). For more detail on this seeDebug Web Vitals in the field.

js
function getCLSDebugTarget(entries) {  const largestEntry = entries.reduce((a, b) =>    a && a.value > b.value ? a : b,  );  if (largestEntry?.sources?.length) {    const largestSource = largestEntry.sources.reduce((a, b) => {      const area = (el) => el.previousRect.width * el.previousRect.height;      return a.node && area(a) > area(b) ? a : b;    });    if (largestSource) {      return largestSource.node;    }  }}

Specifications

Specification
Layout Instability API
# sec-layout-shift-attribution

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp