PerformanceElementTiming: naturalHeight プロパティ

Limited availability

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

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

ブラウザーの互換性

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
naturalHeight
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.