gyzhor
08-25-2010, 07:52 PM
Hi CF,
I'm a graphic/designer and occasional Actionscript developer making what's turning out to be a rather clumsy transition into Javascript. Be gentle. :D
I'm trying to create a script that will load an external image and test whether it's in my document's "tall" or "wide" formats before placing it in the page.
This is easy in IE just using imageObject.width, but Firefox seems to always return a value of 0, no matter what I do (this includes using imageObject.naturalWidth).
Refreshing the page suddenly causes the wide mode to activate, but any time before the image is actually placed in the document, FF just won't read the width.
I've tried maybe a dozen different scripts, but here's my most recent:
function testImage(){
if (defaultImage.naturalWidth > 320){
wideMode = true;
}
placeImage();
}
function loadFirstImage(){
defaultImage.src = "images/myGIF.gif";
defaultImage.onLoad = testImage();
}
Any ideas on how to accurately get an image object's width after loading, but before placing it on the page?
Any help is much appreciated.
Thanks,
~gyz
I'm a graphic/designer and occasional Actionscript developer making what's turning out to be a rather clumsy transition into Javascript. Be gentle. :D
I'm trying to create a script that will load an external image and test whether it's in my document's "tall" or "wide" formats before placing it in the page.
This is easy in IE just using imageObject.width, but Firefox seems to always return a value of 0, no matter what I do (this includes using imageObject.naturalWidth).
Refreshing the page suddenly causes the wide mode to activate, but any time before the image is actually placed in the document, FF just won't read the width.
I've tried maybe a dozen different scripts, but here's my most recent:
function testImage(){
if (defaultImage.naturalWidth > 320){
wideMode = true;
}
placeImage();
}
function loadFirstImage(){
defaultImage.src = "images/myGIF.gif";
defaultImage.onLoad = testImage();
}
Any ideas on how to accurately get an image object's width after loading, but before placing it on the page?
Any help is much appreciated.
Thanks,
~gyz