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
This is my method, hope this helpful. :)
Using JQuery you do this:
The thing all other have forgot is that you cant check image size before it loads. When the author checks all of posted methods it will work probably only on localhost. Since jQuery could be used here, remember that 'ready' event is fired before images are loaded. $('#xxx').width() and .height() should be fired in onload event or later.
Nicky De Maeyer asked after a background picture; I simply get it from the css and replace the "url()":
You can apply the onload handler property when the page loads in js or jquery like this:-