显示图片,比例不变,

sirzxj 2010-10-15 08:52:47
并且,
大了,
自动缩小,
小了
自动放大
是怎么实现的
...全文
119 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wwfgu00ing 2010-10-15
  • 打赏
  • 举报
回复
<img src="img/me.jpg" onload="javascript:if(this.width>200)this.width=200;" >
happy664618843 2010-10-15
  • 打赏
  • 举报
回复
# function Wa_SetImgAutoSize(img) {  
# var MaxWidth = 200;
# var MaxHeigth = 200;
# var heightwidth = img.offsetHeight / img.offsetWidth;//设置高宽比
# var widthheight = img.offsetWidth / img.offsetHeight; //设置宽高比
# alert("文件的宽:"+img.offsetWidth);
# alert("文件大小:" + img.fileSize / (1024 * 1024) + "MB");
# if (img.readyState != "complete")
# return false;
# if (img.offsetWidth > MaxWidth)
# {
# img.width = MaxWidth;
# //宽度乘以 高宽比
# img.heigth = MaxWidth * heightwidth;
# }
# if (img.offsetHeight > MaxHeigth) {
# //设置图片的高度
# img.height = MaxHeigth;
# //设置图片的宽度 最大的高度乘以 宽 高比
# img.width = MaxHeigth * widthheight;
# }
#
# }
wuyq11 2010-10-15
  • 打赏
  • 举报
回复
等比例缩放图片
<script language="JavaScript">
var flag=false;
function DrawImage(ImgD,iwidth,iheight){
var image=new Image();
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;
}

}
}onload="javascript:DrawImage1(this)">
koukoujiayi 2010-10-15
  • 打赏
  • 举报
回复
抱歉!1楼看错了!!
孟子E章 2010-10-15
  • 打赏
  • 举报
回复
<img onload="if(this.width!=200) this.width=200"
koukoujiayi 2010-10-15
  • 打赏
  • 举报
回复
image控件不要设置大小!

62,272

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧