Are there any jQuery or pure JS APIs or methods to get the dimensions of an image on the page?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- How to get the background from multiple images by
- How to fix IE ClearType + jQuery opacity problem i
it is important to remove the browser interpreted setting from the parent div. So if you want the real image width and height you can just use
This is one TYPO3 Project example from me where I need the real properties of the image to scale it with the right relation.
You can only really do this using a callback of the load event as the size of the image is not known until it has actually finished loading. Something like the code below...
clientWidth and clientHeight are DOM properties that show the current in-browser size of the inner dimensions of a DOM element (excluding margin and border). So in the case of an IMG element, this will get the actual dimensions of the visible image.
Before acquire element's attributes,the document page should be onload:
ok guys, i think i improved the source code to be able to let the image load before trying to find out its properties, otherwise it will display '0 * 0', because the next statement would have been called before the file was loaded into the browser. Requires jquery...