I have a image resizer function that resize images proportional. On every image load a call this function with image and resize if its width or height is bigger than my max width and max height. I can get img.width and img.height in FF Chrome Opera Safari but IE fails. How can i handle this?
Let me explain with a piece of code.
<img src="images/img01.png" onload="window.onImageLoad(this, 120, 120)" /> function onImageLoad(img, maxWidth, maxHeight) { var width = img.width; // Problem is in here var height = img.height // Problem is in here }
In my highligted lines img.width don't work on IE series.
Any suggestion?
Thanks.
Answer: Use the JavaScript clientWidth property You can simply use the JavaScript clientWidth property to get the current width and height of an image. This property will round the value to an integer.
width(); alert(imageWidth); var imageHeight = Imgsize. height();
Don't use width
and height
. Use naturalWidth
and naturalHeight
instead. These provide the image unscaled pixel dimensions from the image file and will work across browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With