tags:

views:

30

answers:

1

Hi all,

I'm getting users profile pictures from Facebook so their loading time varies quite a lot. When they have loaded I want to resize them. I have the resizing code working OK, but cannot get the actual code to execute reliably at the right time. According to the info I've found this should work:

$('.userPic').load(function () {

... code to resize pictures

});

But it doesn't seem 100% reliable. Any other hints or tips?

Thanks Nick Swan

A: 

This is strange, when page has finished loading, it has also loaded all internal and external resources. Check to make sure that if jquery gives you its width, if so, it is loaded:

$('.userPic').load(function () {
  if ($(this).width()){
    // resize code....
  }
  else{
    // still loading....
  }
});

The width() gives the calculated width which is possible when image has successfully loaded.

Update

Use the load even instead of ready handler to make sure that all images are loaded before your code runs:

$(window).load(function(){
  // your code here.......
});
Sarfraz
The actual page I'm trying this on is www.3goodshots.com - see if the images all resize to relatively small for you? Thx
Nick Swan
@Nick Swan: How much small do you mean? Also see my updated answer please.
Sarfraz
They shouldn't be bigger than 100px big in width or height. I think it may have been something to do with the large versions being cached. I've cleared temp files and it seems to be working OK now
Nick Swan
@Nick Swan: ok it is good news then.....
Sarfraz