<script language="JavaScript"><!--//图片按比例缩放var flag=false;function DrawImage(ImgD,iwidth,iheight){ //参数(图片,允许的宽度,允许的高度) 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>
图片按比例缩放
最新推荐文章于 2022-06-12 09:17:57 发布
本文介绍了一段用于按比例缩放图片的JavaScript脚本代码。该脚本通过检测图片原始尺寸与目标显示区域的大小来调整图片的宽高比,确保图片在不同设备和窗口尺寸下能够适配并保持原有比例。
3978

被折叠的 条评论
为什么被折叠?



