縮放圖片腳本分享
TML PUBL "- / /W3C//DTD HTML 4.01 轉場//EN" "http://www.w3.org/TR/html4/loose.dtd">
新文件
function AutoResizeImage(maxWidth,maxHeight){
var objImg = document.getElementByIdum( "operImg");
var img = new Image();
img.src = objImg.src;
var hRatio;
var wRatio;
var 比率= 1;
var wRatio;
var 比率= 1;
var wRatio;
var 比率= 1;
var wRatio;
var 比率= 1;
var wRatio;
var 比率= 1;
var wRatio;
var 比率= 1;
var wRatio; var w = img.width;
var h = img.height;
wRatio = maxWidth / w;
hRatio = maxHeight / h;
if (maxWidth ==0 && maxHeight==0) {
比率= 1;
}else if (maxWidth==0){//
if (hRatio}else if (maxHeight==0){
if (wRatio}else if (wRatioRatio = (wRatio}
}
if (比率w = w * 比率;
h = h * 比率;
}
objImg.height = h;
objImg.width = w;
}
腳本>
頭>
重點:
js:
複製程式碼
程式碼如下:
function AutoResizeImage(maxWidthth maxHeight){ var img = new Image();
img.src = objImg.src;
var hRatio;
var wRatio;
var 比率= 1;
var w = img.width;
var h = img.height;
wRatio = maxWidth / w;
hRatio = maxHeight / h;
if (maxWidth ==0 &maxHeightth ==0 &maxHeight =0){
比率= 1;
}else if (maxWidth==0){//
if (hRatio}else if (maxHeight==0 ){
if (wRatio}else if (wRatioRatio = (wRatio} if (比率w = w * 比值; h = h * 比值; } objImg.height = h; objImg.width =objImg.height = h; objImg.width = w; }