Copy Code code as follows:
/*
* Image preload and Auto zoom
* Scaling is equal scale automatic scaling
* Width Picture Maximum height
* Height Picture Maximum width
* Loadpic the picture path in load
* Example $ ("*"). LoadImage (TRUE,W,H);
*/
Jquery.fn.loadimage=function (scaling,width,height,loadpic) {
if (loadpic==null) loadpic= ". /images/loading.gif ";
Return This.each (function () {
var t=$ (this);
var src=$ (this). attr ("src")
var img=new Image ();
Alert ("Loading ...")
IMG.SRC=SRC;
Automatically scale pictures
var autoscaling=function () {
if (scaling) {
if (img.width>0 && img.height>0) {
if (img.width/img.height>=width/height) {
if (img.width>width) {
T.width (width);
T.height ((img.height*width)/img.width);
T.css ("Margin-top", (Height-t.height ())/2);
}else{
T.width (Img.width);
T.height (Img.height);
T.css ("Margin-top", (Height-t.height ())/2);
}
}
else{
if (img.height>height) {
T.height (height);
T.width ((img.width*height)/img.height);
T.css ("Margin-top", (Height-t.height ())/2);
}else{
T.width (Img.width);
T.height (Img.height);
T.css ("Margin-top", (Height-t.height ())/2);
}
}
}
}
}
Cached pictures are automatically read under processing FF
if (img.complete) {
Alert ("gettocache!");
AutoScaling ();
Return
}
$ (this). attr ("src", "");
var loading=$ ("T.hide ();
T.after (loading);
$ (IMG). Load (function () {
AutoScaling ();
Loading.remove ();
T.attr ("src", this.src);
T.show ();
Alert ("finally!")
});
});
}