首页 > 网站 > WEB开发 > 正文

百度源代码里的精妙javascript图片大小处理函数

2024-04-27 14:01:25
字体:
来源:转载
供稿:网友

<script language=javascript>
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;
                  }
      }
}

</script>


<img src="http://www.baidu.com/images/logo.gif" onload=proDownImage(this); />


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表