/* ************************** (c)2010-2015 phpmywind.com update: 2012-6-11 15:44:16 person: feng ************************** */ (function($) { jquery.fn.loadimage = function(settings) { settings = jquery.extend({ scaling: true, width: 240, height: 150, loadpic: "templates/default/images/loading2.jpg" },settings); return this.each(function() { $.fn.loadimage.showimg($(this), settings) }) }; $.fn.loadimage.showimg = function($this, settings) { var loading = $("\"图片加载中..\""); $this.hide(); $this.after(loading); var autoscaling = function() { if (settings.scaling) { if (img.width > 0 && img.height > 0) { 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) } } } } } var src = $this.attr("src"); var img = new image(); img.onload = function(){ autoscaling(); $this.attr("src", src); $this.show(); loading.remove(); }; img.src = src; //$.ajaxsetup ({ cache: false }); /* $(img).load(function() {*/ // }) } })(jquery);