百度源代码里的精妙javascript图片大小处理函数
2008-08-28 19:59:20 来源:WEB开发网核心提示:<script language=javascript>var PRoMaxHeight = 150;var proMaxWidth = 110;function proDownImage(ImgD){ var image=new Image(); image.src=ImgD.src; if(ima
<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://tech.cncms.com/tech/UploadPic/2010910/2010910195920953.gif" onload=proDownImage(this); />
更多精彩
赞助商链接