raterus
asked on
Preloading images, and getting width/height
I'm have a need when my page loads to a) Load an image and then b) get the width/height. The problem I'm running into, at least in firefox, is when the image is first loaded, the width/height are reported incorrectly. However, if I refresh the page, and the browser loads from cache, the correct width/heights are recorded.
Here's what I'm doing
iW & iH return 24px on the first page load, but subsequent page loads return the correct dimensions of the image
It seems pretty straightforward, but doesn't work as you'd expect in firefox. Can anyone suggest some ideas to actually preload the image?
Here's what I'm doing
var fppImage = $('<img />');
fppImage.attr('src', '/some/image/url.jpg').appendTo('body');
var iH = fppImage.height();
var iW = fppImage.width();
alert(iW + " " + iH);
iW & iH return 24px on the first page load, but subsequent page loads return the correct dimensions of the image
It seems pretty straightforward, but doesn't work as you'd expect in firefox. Can anyone suggest some ideas to actually preload the image?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.