起点设计资源网提供更多的素材下载资源,让你设计工作更方便!
高级搜索 收藏本站 网站地图 RSS订阅 最新专题

JAVASCRIPT

缩小图片不失真的解决方法

『 更新时间:2008-06-21 』『 字体: 』『 作者:佚名 |  来源:本站原创 』

<!--如何让图片强制缩小后不会失真,最新解决方法-->
<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>= 105/80){
  if(image.width>105){
    ImgD.width=105;
    ImgD.height=(image.height*105)/image.width;
  }else{
    ImgD.width=image.width;
    ImgD.height=image.height;
  }
  ImgD.alt="点击查看详细信息...";
  }
  else{
  if(image.height>80){
    ImgD.height=80;
    ImgD.width=(image.width*80)/image.height;
  }else{
    ImgD.width=image.width;
    ImgD.height=image.height;
  }
  ImgD.alt="点击查看详细信息...";
  }
}
}
//-->
</script>

字串4

<TD width="105" height="85" align="center" bgcolor="#E9E9E9">
      <a href='ProductShow.asp?ID=104' target=_blank title='除异味系列'>
 
        <img src="UploadFiles/2006112016052254.jpg" alt="除异味系列" width="105" height="80" border="0" onload="javascript:DrawImage(this);">
  </a>
     
      </TD>
将以上的代码放在你的网页上试试吧
可能是你想要的哦

字串9