控制图片长度比例,及图片最大高度,最大宽度 JS代码

来源:互联网 发布:软件开发委托合同 编辑:程序博客网 时间:2024/05/19 13:29
 

  <script language="javascript" >
 
<!--
var flag=false;
function DrawImage(ImgD){
 var image=new Image();
 image.src=ImgD.src;
 if(image.width>0 && image.height>0){
  flag=true;
  if(image.width/image.height>= 120/72){
   if(image.width>120){
    ImgD.width=120;
    ImgD.height=(image.height*120)/image.width;
   }else{
    ImgD.width=image.width;
    ImgD.height=image.height;
   }
   ImgD.alt="点击查看详细信息...";
  }
  else{
   if(image.height>72){
    ImgD.height=72;
    ImgD.width=(image.width*72)/image.height;
   }else{
    ImgD.width=image.width;
    ImgD.height=image.height;
   }
   ImgD.alt="点击查看详细信息...";
  }
 }
}

//-->
 
 </script>

 

<img src="http://ah158.net/images/logo.jpg" width='120' height='80' border=0  onload='javascript:DrawImage(this);'  />
原创粉丝点击