[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/API/HTMLImageElement/naturalHeight [Back]  [Original]

HTMLImageElement: naturalHeight - Web API | MDN

MDN Web Docs

View in English Always switch to English

HTMLImageElement: naturalHeight

Baseline

20157

HTMLImageElement naturalHeight CSS

: Chrome naturalHeight

CSS height

naturalHeight 0

CSS

HTML

html
<div class="box">
  <img
    src="/ja/docs/Web/HTML/Reference/Elements/img/clock-demo-400px.png"
    class="image"
    alt="" />
</div>
<pre></pre>

HTML 400x398 <div>

CSS

css
.box {
  width: 200px;
  height: 200px;
}

.image {
  width: 100%;
}

CSS 200px 100%

JavaScript

js
const output = document.querySelector("pre");
const image = document.querySelector("img");

image.addEventListener("load", (event) => {
  const { naturalWidth, naturalHeight, width, height } = image;
  output.textContent = `
: ${naturalWidth} x ${naturalHeight} 
: ${width} x ${height} 
`;
});

JavaScript <pre> load

HTML
# dom-img-naturalheight-dev


Web Proxy Viewer  |  New URL  |  Original Page