如何自动调整图片的大小,使它不超出表格以外,或是把表格撑开?
如何自动调整图片的大小,使它不超出表格以外,或是把表格撑开? 问题点数:20、回复次数:8Top
1 楼smallyear(再見理想)回复于 2004-08-03 15:42:07 得分 0
<td><img width=100% height=100% border=0></td>Top
2 楼juge828(笨鸟要早点飞)回复于 2004-08-03 15:54:26 得分 0
<td><img width=100% height=100% border=0></td>
高度不要设,那么图片大小缩放就按原来的比例了
Top
3 楼ycted(长城万里今犹在,不见当年秦始皇!)回复于 2004-08-03 15:58:30 得分 0
smallyear的可能还是会把表格撑破.所以对于width还是要规定个值.不过这样可能会造成图片的变形.你可以考虑如果图片大于你所规定的大小就自动裁减图片的程序.我记的原来这里有人贴了代码的.你可以去找找.
Top
4 楼smallyear(再見理想)回复于 2004-08-03 16:16:02 得分 0
如果要圖片不變形﹐當然不能這樣設了﹐還得判斷Top
5 楼yexing(猪猪爱波波)回复于 2004-08-03 16:36:20 得分 0
在img的onload里面检测表格大小,这是最通用的做法Top
6 楼sword222()回复于 2004-08-21 13:56:05 得分 0
<img src="" width="宽" height="高" name="tupian">
这样就可以控制高和宽了。Top
7 楼ambitionsky(ambition)回复于 2004-08-21 14:05:06 得分 0
fTop
8 楼mackyliu(才子-54caizi.com)回复于 2004-08-21 14:14:29 得分 20
<script language="JavaScript">
<!--
//图片按比例缩放
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 120; //定义允许图片宽度
var iheight = 90; //定义允许图片高度
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;
}
}
}
//-->
</script>
Top




