很多時間特別是文章都會有圖片是吧
jquery
fn autozoomloadimage = function(scaling width height loadpic) {
if (loadpic == null) loadpic = "loadinggif";
return thiseach(function() {
var t = $(this);
var src = $(this)attr("src");
var img = new image();
//alert("loading")
imgsrc = src;
//自動縮放圖片
var autoscaling = function() {
if (scaling) {
if (imgwidth > && img height > ) {
if (imgwidth / img height >= width / height) {
if (imgwidth > width) {
twidth(width);
theight((img height * width) / img width);
}
else {
twidth(img width);
theight(img height);
}
}
else {
if (imgheight > height) {
theight(height);
twidth((img width * height) / img height);
}
else {
twidth(img width);
theight(img height);
}
}
}
}
}
//處理ff下會自動讀取緩存圖片 jquery圖片等比例縮放程序
if (imgcomplete) {
//alert("gettocache!");
autoscaling();
return;
}
$(this)attr("src" "");
var loading = $("<img alt="加載中" title="圖片加載中" src="" + loadpic + "" />");
thide();
tafter(loading);
$(img)load(function() {
autoscaling();
loadingremove();
tattr("src" this src);
tshow();
//alert("finally!")
});
});
}
From:http://tw.wingwit.com/Article/program/Java/hx/201404/30475.html