HTML DOM Image NaturalWidth Property - W3Schools
Có thể bạn quan tâm
❮ Image Object
Example
Return the original width of an image:
var x = document.getElementById("myImg").naturalWidth; Try it Yourself »Description
The naturalWidth property returns the original width of an image.
For example, if you have an image that is originally 100 pixels wide. Then, you style the image with CSS/or by using the HTML "width" attribute to make it 500 pixels wide. The naturalWidth property will return "100", the width property however, will return 500.
Tip: Use the naturalHeight property to return the original height of an image, or the height property to set or return the value of the height attribute of an image.
Note: This property is read-only.
Browser Support
| Property | |||||
|---|---|---|---|---|---|
| naturalWidth | Yes | 9.0 | Yes | Yes | Yes |
Syntax
imageObject.naturalWidthTechnical Details
| Return Value: | A Number, representing the original width of an image in pixels |
|---|
More Examples
Example
The difference between the naturalWidth property and the width property:
var x = document.getElementById("myImg").naturalWidth;var y = document.getElementById("myImg").width; Try it Yourself » ❮ Image Object ★ +1 Sign in to track progressTừ khóa » Html Image Original Width
-
How To Get Original Image Size (Width & Height) In JavaScript
-
CSS Image Max-width Set To Original Image Size? - Stack Overflow
-
How To Resize An Image In HTML?
-
HTML Tag: Change The Width Of A Picture In HTML »
-
HTML Img Width Attribute - W3Schools
-
Setting Height And Width On Images Is Important Again
-
Width And Height Of An Image - HTML Tags - TAG Index
-
How To Keep Dimensions Css Image Code Example - Code Grepper
-
How To Set The Width And Height Of An Image Using HTML
-
HTML Tutorial => Image Width And Height
-
C37: Using CSS Max-width And Height To Fit Images
-
How To Get Image Size Using JavaScript - W3docs
-
HTML Img Width Attribute - Dofactory
-
How To Resize An Image With HTML - Computer Hope