Return the original width of an image:
The result of x will be:
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.
The naturalWidth property is supported in all major browsers.
Return Value: | A Number, representing the original width of an image in pixels |
---|
The difference between the naturalWidth property and the width property: