/* ///来源 http://wwww.css88.com ///参数设置: scaling 是否等比例自动缩放 width 图片最大高 height 图片最大宽 loadpic 加载中的图片路径 */ (function($){ jQuery.fn.LoadImage=function(settings){ settings = jQuery.extend({ scaling : true, width : 600, height : 800, loadpic:"" }, settings); return this.each(function() { $.fn.LoadImage.Showimg( $( this ), settings ); }); }; $.fn.LoadImage.Showimg = function($this, settings){ var src=$this.attr("src"); var width=$this.attr("width"); var height=$this.attr("height"); var img=new Image(); img.src=src; var autoScaling=function(){ if (settings.scaling) { if (img.width > 0 && img.height > 0) { if(width / height >= settings.width / settings.height){ if (width > settings.width) { $this.width(settings.width); $this.height((height * settings.width) / width); }else { $this.width(width); $this.height(height); } }else if(img.width / img.height >= settings.width / settings.height) { if (img.width > settings.width) { $this.width(settings.width); $this.height((img.height * settings.width) / img.width); }else { $this.width(img.width); $this.height(img.height); } }else { if (img.height > settings.height) { $this.height(settings.height); $this.width((img.width * settings.height) / img.height); } else { $this.width(img.width); $this.height(img.height); } } } } } $this.attr("src",""); var loading=$("\"loading...\""); $this.hide(); $this.after(loading); /*$(img).load(function(){ autoScaling(); loading.remove(); $this.attr("src",this.src); $this.show(); });*/ $(img).load(function(){ autoScaling(); loading.remove(); $this.attr("src",this.src); $this.show(); }).each(function() { if(this.complete) $(this).load(); }); } })(jQuery);