编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛  
全能 ASP / PHP / ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
发新话题
打印

请教:用什么方法可以将图片按比例缩放,但又不是按实际图片大小来显示.使之不变形.

请教:用什么方法可以将图片按比例缩放,但又不是按实际图片大小来显示.使之不变形.

请教:如何将图片按比例缩放,使之不变形.
<img border="0" src="<%=pic_url%>" width="120" height="120" align="left" alt="点击查看图片">

TOP

用Javascript,我做过,挺不错的。自己想。
. 为钱而战

TOP

复制内容到剪贴板
代码:
<script language="javascript">  
  function aa(n){
    var img_h=n.clientHeight;
    var img_w=n.offsetWidth;
    
    //缩小50%
    n.height=img_h*0.5;
    n.width=img_w*0.5;
     }
</script>
<body>
<img  src="http://bbs.bccn.net/ad/suhai_468_60.gif" onLoad="aa(this)">
</body>
[ 本帖最后由 hugeannex 于 2008-6-12 00:01 编辑 ]
. 为钱而战

TOP

<img border=0 src="http://bbs.bccn.net/images/default/logo.gif" onload="javascript:if(this.width>800)this.width=800">
2000年接触asp     2002年精通asp     2004年熟悉asp    2006年基本了解asp    2008年真搞不懂asp

TOP

只要不是同时设置 width="120" 和 height="120",总是按比例显示的哦!

TOP

//图像按比例缩小JS函数
function SmallImg(ImgD){
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= 120/90){
     if(image.width>120){
         ImgD.width=120;
         ImgD.height=(image.height*120)/image.width;
     }else{
         ImgD.width=image.width;
         ImgD.height=image.height;
     }
    }
    else{
     if(image.height>90){
         ImgD.height=90;
         ImgD.width=(image.width*90)/image.height;
     }else{
         ImgD.width=image.width;
         ImgD.height=image.height;
     }
    }
  }
}

<img  src="http://bbs.bccn.net/ad/suhai_468_60.gif" onLoad="SmallImg(this)">
从明天起作个幸福的人、喂马劈柴周游世界

TOP

发新话题