`

精妙javascript图片大小处理函数

    博客分类:
  • Web
阅读更多
写道

var proMaxHeight = 150;
var proMaxWidth = 110;
  
function proDownImage(ImgD){
   var image=new Image();
   image.src=ImgD.src;
   if(image.width>0 && image.height>0){
   var rate = (proMaxWidth/image.width < proMaxHeight/image.height)?proMaxWidth/image.width:proMaxHeight/image.height;
  if(rate <= 1){ 
   ImgD.width = image.width*rate;
   ImgD.height =image.height*rate;
  }
  else {
              ImgD.width = image.width;
             ImgD.height =image.height;
         }
   }
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics