// 图片等比例缩放效果 方法一 、
function fixImage(i,w,h){ var ow = i.width; var oh = i.height; var rw = w/ow; var rh = h/oh; var r = Math.min(rw,rh); if (w ==0 && h == 0){ r = 1; }else if (w == 0){ r = rh<1?rh:1; }else if (h == 0){ r = rw<1?rw:1; } if(ow!=0 && oh!=0){ i.width = ow * r; i.height = oh * r; }else{ var __method = this, args = $A(arguments); window.setTimeout(function() { fixImage.apply(__method, args); }, 200); } i.onload = function(){} } // 图片等比例缩放效果 方法二、function DrawImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度) if(ImgD.width>0 && ImgD.height>0){ flag=true; // 如果图片的实际比例大于的想要比例 ,则去根据宽大小来判断高 if(ImgD.width/ImgD.height>= iwidth/iheight){ if(ImgD.width>iwidth){ ImgD.width=iwidth; ImgD.height=(ImgD.height*iwidth)/ImgD.width; } ImgD.alt=ImgD.width+"×"+ImgD.height; }else{ if(ImgD.height>iheight){ ImgD.height=iheight; ImgD.width=(ImgD.width*iheight)/ImgD.height; } ImgD.alt=ImgD.width+"×"+ImgD.height; } } }