net 图片等比例缩放

<script language="jscript" type="text/javascript">
    var flag=false;
function FormatImg(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 500/370){
   if(image.width>500){
   ImgD.width=500;
   ImgD.height=(image.height*500)/image.width;
   }else{
   ImgD.width=image.width;
   ImgD.height=image.height;
   }
   }
   else{
   if(image.height>370){
   ImgD.height=370;
   ImgD.width=(image.width*370)/image.height;
   }else{
   ImgD.width=image.width;
   ImgD.height=image.height;
   }
}
}
}
</script>

 

<img id="ima<%# DataBinder.Eval(Container.DataItem, "iProductId")%>" name="Image1"
                                                                            border="0" width="141" height="141" onload="FormatImg(ima<%# DataBinder.Eval(Container.DataItem, "iProductId")%>);"
                                                                            src='<%# Eval("varProduct_Img").ToString().Substring(2,Eval("varProduct_Img").ToString().Length-2) %>' />

posted on 2009-12-28 10:39  峫噁Da兎兎  阅读(201)  评论(0编辑  收藏  举报