tags:

views:

33

answers:

1

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.

+2  A: 

try

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

required jQuery 1.4

Reigel
Hi, thanks for such a quick reply. That does not seem to be having any effect on the image size. I'm linking to jQuery 1.4.2 Here is what I am using to be exact: <script type="text/javascript"> $('#tumblr img').load(function () { $(this).css('width', function (i, width) { return (parseInt(width) > 435) ? '435px' : width; }); }); </script>
liquilife
you must do it in every new images... if you can post your code on how that happens, I could help you... just edit your post with the codes..
Reigel