您的位置:首页 > Web前端 > JavaScript

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

2014-04-26 08:11 417 查看
<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="" onload=proDownImage(this); />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: