At first you should wait while image gets loaded.
If you run your script after window.onload fired and image is created static
with <image src="..."> than image is loaded.
But if you create image with javascript createElement('image') you should
have image onload or onreadystatechange handlers.
Try element.*offsetWidth *to get width and element.*offsetHeight *for height
Also if offsetWidth doesn't work for some reasons (and you work in mozilla)
you can try methods element.getBoundingClientRect() which returns structure
with left, top,right,bottom fields, or document.getBoxObjectFor(element)
As far as I remember they work in different versions of mozilla's gecko
On Fri, Oct 8, 2010 at 9:27 PM, Tom Brito <
brito.pro@gmai...> wrote:
> Hi!
>
> I'm working with images, and if I don't specify an width and height to an
> image it fits the exactly size of the image (didn't tested for images larger
> then the screen).
>
> What I would like to do is get the width of this loaded image, so I can
> calculate to put it in the center of the screen with (screen/width/2 -
> image.width/2),
> any idea how to get loaded image's width?
>
> Trying with:
>
> var image = getElementById('loadingImage');
>
>
> image.width returns nothing..
>
>
> *
> Wellington B. de Carvalho
> *
>
>
> ------------------------------------------------------------------------------
> Beautiful is writing same markup. Internet Explorer 9 supports
> standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
> Spend less time writing and rewriting code and more time creating great
> experiences on the web. Be a part of the beta today.
>
http://p.sf.net/sfu/beautyoftheweb
> _______________________________________________
> XUL News Wire -
http://xulnews.com
> XUL Job Postings -
http://xuljobs.com
> Open XUL Alliance -
http://xulalliance.org
> _______________________________________________
> xul-talk mailing list
>
xul-talk@list...
>
https://lists.sourceforge.net/lists/listinfo/xul-talk
>
>
opensubscriber is not affiliated with the authors of this message nor responsible for its content.