缩放代码: 复制代码 代码如下: 缩放代码: <br>//图片按比例缩放 <br>var flag = false; <br>function DrawImage(ImgD, iwidth, iheight) { <br>//参数(图片,允许的宽度,允许的高度) <br>var image = new Image(); <br>image.src = ImgD.src; <br>if (image.width > 0 && image.height > 0) { <br>flag = true; <br>if (image.width / image.height >= iwidth / iheight) { <br>if (image.width > iwidth) { <br>ImgD.width = iwidth; <br>ImgD.height = (image.height * iwidth) / image.width; <br>} else { <br>ImgD.width = image.width; <br>ImgD.height = image.height; <br>} <br>ImgD.alt = image.width "×" image.height; <br>} <br>else { <br>if (image.height > iheight) { <br>ImgD.height = iheight; <br>ImgD.width = (image.width * iheight) / image.height; <br>} else { <br>ImgD.width = image.width; <br>ImgD.height = image.height; <br>} <br>ImgD.alt = image.width "×" image.height; <br>} <br>} <br>} <br> 页面代码: 觉得不错的发个言! 页面代码: 1. 觉得不错的发个言!