This article illustrates how jquery implements automatic scaling of pictures based on the size of the browser window. Share to everyone for your reference. as follows:
(function ($) {$.fn.resizeimage = function () {var imgload = function (URL, callback) {var img = new Image ();
img.src = URL;
if (Img.complete) {callback (img.width, img.height);
else {img.onload = function () {callback (img.width, img.height);
Img.onload = null;
};
};
};
var original = {width:$ (window). width ()};
Return This.each (function (i,dom) {var-image = $ (this); Imgload (image.attr (' src '), function () {var img = {width:image.width (), Height:image.height ()},percentag
e=1;
if (img.width<original.width) {percentage = 1;
}else{percentage = (original.width)/img.width;
} image.width (img.w=img.width*percentage-30). Height (img.h=img.height*percentage);
$ (window). Resize (function () {var w = $ (this). width ();
Percentage = w/img.width>1?1:w/img.width;
var newwidth = img.width*percentage-30;
var newheight = img.height*percentage; Image.width (newwidth). Height (nEwheight);
});
});
});
};
}) (JQuery);
I hope this article will help you with your jquery programming.