找回密码
 注册
广告投放 虚位以待【阿里云】2核2G云新老同享 99元/年,续费同价做网站就用糖果主机-sugarhosts.comJtti.com-新加坡服务器,美国服务器,香港服务器
查看: 1292|回复: 10

这段限制图片大小的代码该怎么用呢?

[复制链接]
发表于 2007 年 1 月 2 日 18:39:30 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
  1. #cont img { max-width: 400px;max-height: 400px;width:expression(onload=function(){if (this.offsetWidth>this.offsetHeight){this.style.width=(this.offsetWidth > 400)?"400px":"auto"}{this.style.height=(this.offsetHeight < 400)?"auto":"400px"}});border:0px;}
复制代码


我的论坛的图片显示BBcode是

  1. '#IMAGE
  2.                         if isFound(str,"[img=") > 0 AND isFound(str,"[/img]") > 0 AND isFound(str,"javascript:") = 0 then
  3.                                 imageIndex = imageIndex + 1
  4.                                 str= Replace(str,"[img=","<br><img onclick=""userImage" & imageIndex & """ onload=""javascript:if(this.width> screen.width/2) this.width=screen.width/2"" id='userImage" & imageIndex & "' src=")
  5.                                 str = Replace(str,"][/img]",">")
  6.                                                         isChange = false
  7.                         End if
复制代码


该怎么组合呢?
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
发表于 2007 年 1 月 2 日 18:43:24 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
这段代码是css里的,看错了,有用,直接插css里就可以
不过,你把这段加在html的head上面也可以

  1. <script type="text/javascript">
  2. window.onload=function(){
  3. var imgsrc=document.images;
  4. for(i=0;i<imgsrc.length;i++) {
  5. if(imgsrc[i].width>500) {
  6. imgsrc[i].width=499;
  7. }
  8. }
  9. }
  10. </script>
复制代码

[ 本帖最后由 我踏MJ而来 于 2007-1-2 18:55 编辑 ]
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2007 年 1 月 2 日 19:04:22 | 显示全部楼层
直接放到css里就可以了吗
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2007 年 1 月 2 日 19:07:53 | 显示全部楼层
对,但是相对图片的大区域要加个cont的id
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2007 年 1 月 2 日 19:08:03 | 显示全部楼层
我的论坛顶端有一个超宽的图片,所以用了你的代码,那个图片就会变小,但是其他图片不变
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2007 年 1 月 2 日 19:13:24 | 显示全部楼层

  1. <script type="text/javascript">
  2. window.onload=function(){
  3. var imgsrc=document.images;
  4. for(i=0;i<imgsrc.length;i++) {
  5. if(imgsrc[i].width>500 && imgsrc[i].ref!='keep') {
  6. imgsrc[i].width=499;
  7. }
  8. }
  9. }
  10. </script>
复制代码

不想变的图片加一个ref="keep"的属性,具体的限制大小改500和499
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2007 年 1 月 2 日 19:22:16 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
。。。。。。。。。。。
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2007 年 1 月 2 日 19:40:27 | 显示全部楼层
真是太谢谢你啦,我苦恼已久的问题终于解决了,呵呵呵。
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2007 年 1 月 2 日 20:00:24 | 显示全部楼层
小白素强人
膜拜ing
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2007 年 1 月 2 日 20:22:46 | 显示全部楼层

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>css</title>
  6. <style type="text/css">
  7. body {}

  8. img {border:0;}

  9. .article {width:200px; height:100px; background:#ccc;}

  10. .article img {
  11. max-width: 200px;
  12. max-height: 200px;
  13. width:
  14. expression(onload=function(){if (this.offsetWidth>this.offsetHeight)
  15. {this.style.width=(this.offsetWidth > 200)?"200px":"auto"}
  16. {this.style.height=(this.offsetHeight < 200)?"auto":"200px"}
  17. });
  18. }
  19. </style>
  20. </head>
  21. <body>
  22. <div class="article">
  23. <img src="http://jgwy.net/bbs/images/server.gif" />
  24. <br />
  25. <img src="http://www.jgwy.net/bbs/images/smilies/smile.gif" />
  26. <br />
  27. 容器width=200px
  28. </div>
  29. </body>
  30. </html>
复制代码


但注意,expression是相当耗cpu的,不能用太多
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|金光论坛

GMT+8, 2025 年 2 月 5 日 10:47 , Processed in 0.018917 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表