PerformanceElementTiming: naturalHeight プロパティ

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

naturalHeightPerformanceElementTiming インターフェイスの読み取り専用プロパティで、画像要素の内在的な高さを返します。

符号なし 32 ビット整数 (unsigned long) です。 これが画像に適用されている場合は画像の内在的な高さを表し、テキストの場合は 0 となります。

naturalHeight のログ出力

この例では、elementtiming 属性を追加して <image> 要素を監視しています。 PerformanceObserver"element" 型のパフォーマンス項目をすべて取得するために登録され、オブザーバー作成前のデータにアクセスするために buffered フラグを使用しています。画像ファイルの幅は 1000px、高さは 750px あります。 entry.naturalHeight を呼び出すと、ピクセル単位の内在的な高さである 750 を返します。

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.naturalHeight);
    }
  });
});
observer.observe({ type: "element", buffered: true });

仕様書

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

ブラウザーの互換性

BCD tables only load in the browser