/*
********** ****Picture preloading plug-in****************
///Author: Wu Jian (2008-06-23)
///http ://regedit.cnblogs.com
///Description: Display a loading sign before the image is loaded, and display the image after the image is downloaded
Can automatically zoom the image
When this plug-in is used, the page can be loaded first, and the image can be loaded later.
Solve the problem that the layout needs to be expanded after the image is displayed before zooming in.
//Parameter settings:
scaling whether to automatically scale in equal proportions
width maximum height of the image
height maximum width of the image
loadpic path of the loading image
*/
jQuery.fn.LoadImage=function(scaling,width ,height,loadpic){
if(loadpic==null)loadpic="load3.gif";
return this.each(function(){
var t=$(this);
var src=$(this).attr("src")
var img=new Image();
//alert("Loading")
img.src=src;
// Automatically scale images
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);
}else{
t.width(img.width);
t.height(img.height);
}
}
else{
if (img.height>height){
t.height(height);
t.width((img.width*height)/img.height);
}else{
t.width (img.width);
t.height(img.height);
}
}
}
}
}
//It will be read automatically when processing ff Caching images
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!")
});
}) ;
}