liquilife
liquilife

Reputation: 191

Is it possible with jQuery to dynamically resize an image based on the width of it's parent DIV?

I have a DIV tag that will be 500px in width. Content is coming via an RSS feed that includes images. Some of these images are wider then 500px which destroys the layout. Is it possible to use a bit of jQuery to resize images on the fly if they exceed 500px in width and keep the ratio proportionate?

Thanks for any suggestions.

Upvotes: 0

Views: 1071

Answers (1)

Reigel Gallarde
Reigel Gallarde

Reputation: 65274

try

$('img').load(function(){
    $(this).css('width', function(i,width){
        return (parseInt(width) > 500)? '500px':width;
    });
})

required jQuery 1.4

Upvotes: 3

Related Questions