The image itself will also have a load event if your creating it
dynamically:

$('<img src="test.jpg" alt="" /
>').appendTo(document.body).bind("load", function() { ... });

The caveat, though, is that I'm not sure when/if the event gets fired
if the image is cached.  Maybe someone with more experience can
comment on that, but I _think_ that the event actually gets fired when
you create the element (which is before the handler is bound in my
example).  So you might try:

$('<img />').appendTo(document.body).bind("load", function()
{ ... }).attr("src", "test.jpg");

The width() property should be set once the load event fires.  Hope
that helps.

Mark


On Jun 14, 8:00 am, "Erik Beeson" <[EMAIL PROTECTED]> wrote:
> There is a window.load event, and that's what you want to 
> use:http://docs.jquery.com/Events#load.28_fn_.29
>
> So you want:
>
> $(window).load(function() {
>   // My stuff to do once all images are loaded...
>
> });
>
> --Erik
>
> On 6/14/07, GianCarlo Mingati <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
> > the question may not be clear but what i would like to know is how do
> > you get the width of an image AFTER the image has fully downloaded.
> > I use this chunk of code: var pictWidth = this.find("img").width();
> > where "this" is the jQuery context.
>
> > If tested locally (images loads immediately) it works and i have the
> > image WIDTH in pixel, but if i search for anew image (not in cache eg:
> > on a web server)  the script is executed when the DOM is ready, It's
> > to soon, how do i say to jquery "get the width of image#myimage after
> > image#myimage ha fully downloaded?
>
> > For what i understand jQuery only have a DOM iS Ready function.
> >http://demos.mootools.net/DomReadyVS.Load
>
> > I would need a window.load function.
> >http://www.gcmingati.net/wordpress/wp-content/lab/jquery/imagestrip/i...
> > in fact on that page, the gallery won't work correctly if you don't
> > REFRESH the page. When reloaded the images are displayed on the fly
> > and the trick of getting the width of the images works.

Reply via email to