Hey, that's pretty cool Andy. Interesting way to view comics. Glad my little bit of code was able to help.

-- Josh

----- Original Message ----- From: "Andy Matthews" <[EMAIL PROTECTED]>
To: <jquery-en@googlegroups.com>
Sent: Thursday, October 30, 2008 8:09 AM
Subject: [jQuery] Re: Getting width of broken image updated: working now



Josh...

Since you may be curious what I was working on, it's just a little comic
strip viewer for a webcomic called Goats:

http://www.commadelimited.com/code/goats.cfm

It's archives go back roughly 10 years, and I'm trying to work through all
the backlog. Since it's published daily, the archives are approaching 3000
strips. Anywya, I wanted a way to quickly read through back strips, and so I
wrote this little viewer.



andy

-----Original Message-----
From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Josh Nathanson
Sent: Wednesday, October 29, 2008 2:44 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: Getting width of broken image?


Another thing you can try is attach the handler directly to the load event
for each image:

$("img").load(function() {
   alert('image ' + this.src + ' is loaded and has width ' +
$(this).width()); });

This should work ok within document.ready, as the img tags will be loaded in
the DOM and have the event handler bound before the images themselves are
loaded.

-- Josh

----- Original Message -----
From: "Andy Matthews" <[EMAIL PROTECTED]>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Wednesday, October 29, 2008 11:37 AM
Subject: [jQuery] Re: Getting width of broken image?



Hrm...

That "worked", but it's taking longer than I'd like, and it's not
really consistent. I'll just go another route. Thanks for the input
guys.

On Oct 29, 11:44 am, "Josh Nathanson" <[EMAIL PROTECTED]> wrote:
Andy - window.onload is called only after all images are loaded, so you
can
do this:

$(window).load(function() {
$("img").each(function() {
alert( this.offsetWidth>500 );
});

});

-- Josh

----- Original Message -----
From: "Andy Matthews" <[EMAIL PROTECTED]>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Wednesday, October 29, 2008 9:24 AM
Subject: [jQuery] Re: Getting width of broken image?

Okay...

I figured out why it's not working. My code is firing before the
images are fully loaded, therefore the width of the image is zero
until the browser downloads the image.

I installed a click event on each image which reported the actual
width correctly.

So, how might I only run this code AFTER the images have loaded?

$('img').each(function(){
alert(this.offsetWidth>500);
});

Alternately, is there a way to test to see if the image is broken
using jQuery?

On Oct 29, 10:54 am, ricardobeat <[EMAIL PROTECTED]> wrote:
> Besides the bracket weidc mentioned, is your document valid?

> I get the correct image width by using width() on both IE and FF.
> Alternatively you can check for the offsetWidth attribute.

> $('img').each(function(){
> alert(this.offsetWidth>500);

> });

> On Oct 29, 11:30 am, "Andy Matthews" <[EMAIL PROTECTED]>
> wrote:

> > I'm loading in a batch of images dynamically. Some of the images > > might
> > not
> > exist and I'm wondering how I might test for that image using jQuery
> > (1.2.6). All I really want to do is to remove that img from the DOM > > so
> > that
> > it doesn't show on the page.

> > I thought at first it would be simple enough to test the width of the
> > image.
> > All the valid images should be around 600 pixels wide, whereas the
> > broken
> > image should be 30 or so.

> > I tried this:

> > ${'img').each(function(){
> > alert( $(this).width() );

> > });

> > But I got 0 for both a valid, and invalid, image. Anyone have any
> > ideas?

> > andy



Reply via email to