●求解决未知尺寸的图片撑破页面的问题? 放到带scrollbar的div里就可以了吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 奇怪的问题如果onload的不行,再增加其他的事件如onresize onload="javascript:if(this.width>screen.width-700)this.width=screen.width-700"onresize="javascript:if(this.width>screen.width-700)this.width=screen.width-700"就是在onload后面再写 因为图片比较多,用document.images[x].width 也很难知道是哪个 rayFairy 的 onresize 我试过,也没用。不信请看:http://john6688.yp168.com 在放置图片的table 里加上style="table-layout:fixed;word-break:break-all;",table的宽高要有数值哦。这样的话,就不会担心它撑爆页面了,如果过长过高,table就会把它截掉。 用 table 中加css的办法,虽然可以不撑破页面,但这样就不能看到全部缩小后的图片。不是最佳的解决办法。 图片宽度做为300,高度按比例缩放。但把高度限制在500以下。用它来解决问题还是很方便的。function DrawImage(ImgD){ var image=new Image(); image.src=ImgD.src;ImgD.width=300; ImgD.height=300*(image.height/image.width); if(ImgD.height>=500){ ImgD.height=500;}ImgD.alt=ImgD.width+"x"+ImgD.height; }用法:<img src="images/pic/aa.gif" border="0" onload="javascript:DrawImage(this);"> <script language="JavaScript"><!--var flag=false;function DrawImage(ImgD){ var image=new Image(); var iwidth = 150; //设置宽 var iheight = 120; //设置高 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><img src="。" border="0" onload="javascript:DrawImage(this);">试试这个,还可以 <style>img {width:expression((this.width>screen.width-700) ? screen.width-700 : this.width)}</style> 使用以下方法:保证原图片长高比例,且不超过最大高度或宽度function initimg(parpic,maxwidth,maxheight){ var scale=maxwidth/maxheight; var realscale=parpic.width/parpic.height; if((parpic.width>maxwidth)||(parpic.height>maxheight)) { if(realscale>scale) { parpic.width=maxwidth; } else { parpic.height=maxheight; } }}调用方法:图片中加onload事件如下:<img name="carpic" onload="initimg(this,165,176)" src="图片地址">其中165,176,则为强制最大宽度及高度.注意:该方法有时会对.gif格式图片处理失败! nodejs memcached 关于网页加密的问题 onchange事件后,怎么获得焦点? javascript运行在mozilla Firefox中的问题 javascript 把 txt 另存 怎样获得层大小? 如何在一个按钮中调用JS触发检测用户的分辨率 很菜的问题:如何禁止网页的缓存?即某个打开的网页禁止缓存到本地~~ 谢谢 为什么不行呢?帮帮我 JS 数字运算的问题,有点疑惑 有个 Image的 Onload事件造成死循环,不知道该怎么解决? 静态网页中怎样删除按钮所在当前行
如果onload的不行,再增加其他的事件如onresize
就是在onload后面再写
rayFairy 的 onresize 我试过,也没用。不信请看:http://john6688.yp168.com
不是最佳的解决办法。
var image=new Image();
image.src=ImgD.src;
ImgD.width=300;
ImgD.height=300*(image.height/image.width);
if(ImgD.height>=500){
ImgD.height=500;
}
ImgD.alt=ImgD.width+"x"+ImgD.height;
}
用法:<img src="images/pic/aa.gif" border="0" onload="javascript:DrawImage(this);">
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
var iwidth = 150; //设置宽
var iheight = 120; //设置高
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>
<img src="。" border="0" onload="javascript:DrawImage(this);">
试试这个,还可以
img {width:expression((this.width>screen.width-700) ? screen.width-700 : this.width)}
</style>
function initimg(parpic,maxwidth,maxheight)
{
var scale=maxwidth/maxheight;
var realscale=parpic.width/parpic.height;
if((parpic.width>maxwidth)||(parpic.height>maxheight))
{
if(realscale>scale)
{
parpic.width=maxwidth;
}
else
{
parpic.height=maxheight;
}
}
}
调用方法:
图片中加onload事件如下:
<img name="carpic" onload="initimg(this,165,176)" src="图片地址">
其中165,176,则为强制最大宽度及高度.注意:该方法有时会对.gif格式图片处理失败!