图片按比例显示

<scriptlanguage="JavaScript">
<!--
//图片按比例缩放
varflag=false;
functionDrawImage(ImgD){
varimage=newImage();
variwidth=400;//定义允许图片宽度
variheight=400;//定义允许图片高度
image.src=ImgD.src;
if(image.width>0&&image.height>0){
flag=true;
if(image.width/image.height>=iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
//-->
</script>
<imgsrc=".."onload="DrawImage(this)">
阅读更多

没有更多推荐了,返回首页