CSDN博客

img cn2004

成比例缩放图片

发表于2004/10/12 16:16:00  1114人阅读

JavaScript代码:
<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>= 140/125){
     if(image.width>140){ 
     ImgD.width=140;
     ImgD.height=(image.height*140)/image.width;
     }else{
     ImgD.width=image.width; 
     ImgD.height=image.height;
     }
     ImgD.alt=image.width+"×"+image.height;
     }
    else{
     if(image.height>125){ 
     ImgD.height=125;
     ImgD.width=(image.width*125)/image.height;    
     }else{
     ImgD.width=image.width; 
     ImgD.height=image.height;
     }
     ImgD.alt=image.width+"×"+image.height;
     }
    }
}
//-->
</script>

图片引用:
<a target="_blank" href="images/<%=rsmallimg%>">
<img src="images/<%=rsmallimg%>" onload="javascript:DrawImage(this);" alt="<%=rname%>" width="140" height="125" border="0" style="border: 1px solid #000000"></a><BR>
&nbsp; (点击看原图 )

阅读全文
0 0

相关文章推荐

img
取 消
img