PerformanceElementTiming: intersectionRect プロパティ
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental: これは実験的な機能です。
本番で使用する前にブラウザー互換性一覧表をチェックしてください。
intersectionRect は PerformanceElementTiming インターフェイスの読み取り専用プロパティで、ビューポート内の要素の矩形を返します。
値
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> # dom-performanceelementtiming-intersectionrect> |
ブラウザーの互換性
Loading…