【解决马上给分】如果在页面对图片进行放缩,使图片适应指定的大小

zeq258 2010-11-16 10:24:24
如果在页面对图片进行放缩,使图片适应指定的大小。

假设我需要显示图片的地方大小为:(100,100)
如果对其他的图片进行放缩,让它适应这个显示区域。

请给一段展示代码,

谢谢。
...全文
114 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zeq258 2010-11-16
  • 打赏
  • 举报
回复
cj205

(强化练习正则)


非常感谢,问题解决。
bennman 2010-11-16
  • 打赏
  • 举报
回复
img{ width:100%}

自动就根据外层的宽度来缩放了 缺点是 高度不能保证正好填满 顶下一楼
Mr-Jee 2010-11-16
  • 打赏
  • 举报
回复
<img onload=\"DrawImage(this,100,100);\" src="../images/photo/touxiang.jpg" alt="更换头像">
zeq258 2010-11-16
  • 打赏
  • 举报
回复
<a href="/business/changePhoto.jsp" target="mainFrame">
<img src="../images/photo/touxiang.jpg" alt="更换头像">
</a>


这个是我的程序,该如何调用呢。
gentle_sword 2010-11-16
  • 打赏
  • 举报
回复
不错

[Quote=引用 1 楼 cj205 的回复:]
JScript code
function DrawImage(ImgD,iwidth,iheight){
//参数(图片,允许的宽度,允许的高度)
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
……
[/Quote]
Mr-Jee 2010-11-16
  • 打赏
  • 举报
回复
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;
}
}
}

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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