|
自己写的一个非常简单的图片微缩JS代码,当然网上有很多类似的代码,在此确实是献丑了。 主要方法写在SetImgSize.js里面 SetImgSize.js 1 //智能微缩图片JS方法 2 //参数:imgID(图片的标识ID) 3 //参数:maxWidth(图片的最大宽度,值为0则表示不限制宽度) 4 //参数:maxHeight(图片的最大高度,值为0则表示不限制高度) 5 function setImgSize(imgID,maxWidth,maxHeight) 6 { 7 var img = document.images[imgID]; 8 if(maxWidth < 1) 9 { 10 if(img.height > maxHeight) 11 { 12 img.height = maxHeight; 13 } 14 return true; 15 } 16 if(maxHeight < 1) 17 { 18 if(img.width > maxWidth) 19 { 20 img.width = maxWidth; 21 } 22 return true; 23 } 24 if(img.height > maxHeight || img.width > maxWidth) 25 { 26 if((img.height / maxHeight) > (img.width / maxWidth)) 27 { 28 [1] [2] [3] 下一页 |
|
|
|
|
|
|
|