PerformanceElementTiming: intersectionRect プロパティ

Limited availability

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

Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。

intersectionRectPerformanceElementTiming インターフェイスの読み取り専用プロパティで、ビューポート内の要素の矩形を返します。

DOMRectReadOnly で、ビューポートにおけるこの要素の矩形を表します。

表示画像の場合、これはビューポート内の画像の表示矩形です。テキストの場合、これはビューポート内のノードの表示矩形です。これは、要素に属するすべてのテキストノードを結合したものを格納する最小の長方形です。

intersectionRect の出力

この例では、 elementtiming 属性を追加して <img> 要素を監視しています。 PerformanceObserver"element" 型のパフォーマンス項目をすべて取得するために登録され、オブザーバー作成前のデータにアクセスするために buffered フラグを用います。 entry.intersectionRect を呼び出すと、画像の表示矩形を持つ DOMRectReadOnly オブジェクトが返されます。

html
<img
  src="image.jpg"
  alt="a nice image"
  elementtiming="big-image"
  id="myImage" />
js
const observer = new PerformanceObserver((list) => {
  list.getEntries().forEach((entry) => {
    if (entry.identifier === "big-image") {
      console.log(entry.intersectionRect);
    }
  });
});
observer.observe({ type: "element", buffered: true });

仕様書

Specification
Element Timing API
# ref-for-dom-performanceelementtiming-intersectionrect

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
intersectionRect
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.