|
復(fù)制代碼 代碼如下:
縮放代碼:
<script type="text/Javascript">
//圖片按比例縮放
var flag = false;
function DrawImage(ImgD, iwidth, iheight) {
//參數(shù)(圖片,允許的寬度,允許的高度)
var image = new Image();
image.src = ImgD.src;
if (image.width > 0 && image.height > 0) {
flag = true;
if (image.width / image.height >= iwidth / iheight) {
if (image.width > iwidth) {
ImgD.width = iwidth;
ImgD.height = (image.height * iwidth) / image.width;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
ImgD.alt = image.width + "×" + image.height;
}
else {
if (image.height > iheight) {
ImgD.height = iheight;
ImgD.width = (image.width * iheight) / image.height;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
ImgD.alt = image.width + "×" + image.height;
}
}
}
</script>
頁(yè)面代碼:
<img onload="Javascript:DrawImage(this,89,63)" src="http://www.jb51.NET/images/logo.gif" width="89" height="63" border="0" />
覺(jué)得不錯(cuò)的發(fā)個(gè)言!
頁(yè)面代碼:
1. <img onload="Javascript:DrawImage(this,89,63)" src="http://www.baidu.com/img/baidu_logo.gif" width="89" height="63" border="0" />
覺(jué)得不錯(cuò)的發(fā)個(gè)言!
JavaScript技術(shù):js 圖片縮放(按比例)控制代碼,轉(zhuǎn)載需保留來(lái)源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。