Leo Jiang
Leo Jiang

Reputation: 26085

Why isn't this function running?

  $('.posts li img').each(function() {
    if( this.complete )
      imageResize($(this), 64, 64);
    else
      $(this).load(imageResize($(this), 64, 64));
  });

I tried adding "alert('test')" to imageResize(), but it isn't working. Is there any reason why imageResize() isn't being called?

Upvotes: 0

Views: 104

Answers (2)

El Yobo
El Yobo

Reputation: 14946

Not sure that this is the problem, but it's certainly a potential problem. The second imageResize() call will be executed immediately and the return code used as the handler for the load event. You need to wrap it in an anonymous function and use that instead, e.g.

  $('.posts li img').each(function() {
    if( this.complete )
      imageResize($(this), 64, 64);
    else
      $(this).load(function() {imageResize($(this), 64, 64);});
  });

Upvotes: 0

Blender
Blender

Reputation: 298166

Make it a function:

$(this).load(function(this) {imageResize(this, 64, 64)});

Upvotes: 1

Related Questions