【解决马上给分】如果在页面对图片进行放缩,使图片适应指定的大小 如果在页面对图片进行放缩,使图片适应指定的大小。假设我需要显示图片的地方大小为:(100,100)如果对其他的图片进行放缩,让它适应这个显示区域。请给一段展示代码,谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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; } }} <a href="/business/changePhoto.jsp" target="mainFrame"> <img src="../images/photo/touxiang.jpg" alt="更换头像"></a>这个是我的程序,该如何调用呢。 <img onload=\"DrawImage(this,100,100);\" src="../images/photo/touxiang.jpg" alt="更换头像"> img{ width:100%}自动就根据外层的宽度来缩放了 缺点是 高度不能保证正好填满 顶下一楼 js调用,转义问题 请教一个简单的正则表达式问题~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 高分请教一个问题,在线等!!! 两个页面传值的问题 在一个jsp文件中jsp与JavaScript变量如何传递值 大虾们帮忙,一个很弱的问题 请问下js要导入一个30来M的json格式的数组 求子窗口的URL 可否当场获知:多选下拉单中,最新点击的是第几个选项 请问csdn右边展开和关闭的红色三角号是怎么做的??谢谢 求救 JS读取XML 限制图片的大小的脚本
//参数(图片,允许的宽度,允许的高度)
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;
}
}
}
<img src="../images/photo/touxiang.jpg" alt="更换头像">
</a>
这个是我的程序,该如何调用呢。