Monday, 9 July 2012

Resize Images Using JQuery


Write a JQuery function for Image Resizing:


$(document).ready(function(){     $('imgresize').each(function(){         var maxWidth = 500;         var ratio = 0;         var img = $(this);         if(img.width() > maxWidth){             ratio = img.height() / img.width();             img.attr('width', maxWidth);             img.attr('height', (maxWidth*ratio));           }     }); });

This script simply resize your image.

3 comments: