(function ($) {$.fn.resizeimage=function () {varImgload =function (URL, callback) {varIMG =NewImage (); IMG.SRC=URL; if(Img.complete) {callback (img.width, img.height); } Else{img.onload=function () {callback (img.width, img.height); Img.onload=NULL; }; }; }; varOriginal ={width:$ (window). width ()}; return This. Each (function (i,dom) {varImage = $ ( This); Imgload (Image.attr ('src'), function () {varIMG ={width:image.width (), Height:image.height ()},percentage=1; if(img.width<original.width) {Percentage=1; }Else{percentage= (original.width)/Img.width; } image.width (IMG.W=img.width*percentage- -). Height (img.h=img.height*percentage); $ (window). Resize (function () {varW = $ ( This). width (); Percentage= w/img.width>1?1: w/Img.width; varNewwidth = img.width*percentage- -; varNewheight = img.height*percentage; Image.width (newwidth). Height (newheight); }); }); }); };}) (jQuery);
How to use:
$ (' img '). Resizeimage ();
jquery lets pictures scale automatically based on browser window size