views:

28

answers:

1

I use some jquery to centre images on my website:

fixImg = function(){
    w = $(this).width();

    if (w > 500)
        $(this).css('margin', '10px ' + (parseInt((800-w)/2)-30) +'px');
};

$(function() {
    $('#pagecontent img').each(fixImg).load(fixImg);
});

The problem is they only get centered after the entire page has loaded. I use Disqus comments so that can be quite a bit of time on a bad day.

I want to fire this event as soon as the image has a clientWidth which AFAIK, is as soon as it starts to download. Any idea how to do that?

A: 

This question might help you http://stackoverflow.com/questions/1114299/jquery-img-load-question

JKirchartz