西安做网站-西安网站建设-西安网站制作-西安网络公司_千秋网络,app制作下载,网站怎么做才能让更多平台展现,安远做网站在Web上显示图片#xff0c;通常都会有图片显示比例问题#xff0c;如果不给img /限制width和height#xff0c;那么如果图片大了就会将整个页面挤乱#xff0c;图片小了又会使图片失真。我的需求如下#xff1a;1、预先定义好图片显示的标准宽度和高度。2、如果图…在Web上显示图片通常都会有图片显示比例问题如果不给img /限制width和height那么如果图片大了就会将整个页面挤乱图片小了又会使图片失真。 我的需求如下 1、预先定义好图片显示的标准宽度和高度。 2、如果图片的大小超过了标准定义那么等比例压缩图片。 3、如果图片的大小等于标准定义那么按照标准宽度和高度显示图片。 4、如果图片的大小小于标准定义那么不对图片进行任何压缩处理。 可能是我搜索的关键字不对吧在网上找了很长时间才找到感觉很好使。代码如下script languageJavaScript!--//图片按比例缩放var flagfalse;function DrawImage(ImgD,iwidth,iheight){ //参数(图片,允许的宽度,允许的高度) var imagenew Image(); image.srcImgD.src; if(image.width0 image.height0){ flagtrue; if(image.width/image.height iwidth/iheight){ if(image.widthiwidth){ ImgD.widthiwidth; ImgD.height(image.height*iwidth)/image.width; }else{ ImgD.widthimage.width; ImgD.heightimage.height; } ImgD.altimage.width×image.height; } else{ if(image.heightiheight){ ImgD.heightiheight; ImgD.width(image.width*iheight)/image.height; }else{ ImgD.widthimage.width; ImgD.heightimage.height; } ImgD.altimage.width×image.height; } }} //--/script调用img srcimages/toplogo.gif onloadjavascript:DrawImage(this,100,100) 转载于:https://www.cnblogs.com/kingeric/archive/2007/01/01/609476.html