惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
N
News and Events Feed by Topic
P
Privacy International News Feed
The Hacker News
The Hacker News
Schneier on Security
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
Security Latest
Security Latest
L
LINUX DO - 最新话题
阮一峰的网络日志
阮一峰的网络日志
Cisco Talos Blog
Cisco Talos Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
The Cloudflare Blog
博客园 - 【当耐特】
博客园 - Franky
P
Privacy & Cybersecurity Law Blog
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
月光博客
月光博客
D
Docker
Webroot Blog
Webroot Blog
The GitHub Blog
The GitHub Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
W
WeLiveSecurity
S
Security Affairs
Martin Fowler
Martin Fowler
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Archives - TechRepublic
Security Archives - TechRepublic
Microsoft Azure Blog
Microsoft Azure Blog
C
CERT Recently Published Vulnerability Notes
B
Blog
L
Lohrmann on Cybersecurity
T
Threatpost
量子位
S
Schneier on Security
V
Visual Studio Blog
S
Securelist
T
The Exploit Database - CXSecurity.com
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
I
Intezer
Stack Overflow Blog
Stack Overflow Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 聂微东
小众软件
小众软件
罗磊的独立博客
雷峰网
雷峰网
Recorded Future
Recorded Future

博客园 - qqhe325

一个js游戏 向del.icio.us学习 lucene.net优化总结 Fxcop使用笔记 web service 记录1 自定义加密web.config实验记录 DTC:该伙伴事务管理器已经禁止了他对远程/网络事务的支持 C#基础- 抽象类,静态类 js自动加载日期类 当图片路径超出网站根目录时 vs2005宏的问题 asp.net 2.0 access 未指定的错误 oledbparameter在update时出错不报错 grove 小例子 delegate和event例子 你试图打开的项目是Web项目,请指定URL路径 asp.net 在分析向此请求提供服务所需资源时出错 策略模式 我们是怎样的一代人[转]
img的onload事件
qqhe325 · 2007-09-17 · via 博客园 - qqhe325

最近做的东西需要把大图片缩小成不同大小的图片,感觉生成小图片有点浪费资源,而且以后需要不同大小的图片时还要重新生成,不如在前台控制好,这样也灵活。于是就在<img>中加了个onload的事件来在浏览器载入的过程中修改图片的大小,但经过测试发现,onload事件经常没起作用。在网上看了一圈改成下面这个样子

 1 // JScript 文件
 2 //Zeit:2007_09_17
 3 //Ort:shtianxin.com
 4 //Tunesmith:a4647
 5 //Funktion:利用脚本动态改变显示图片的大小,由于img在onload事件上的不灵敏,增加settimeout函数,并用style.display,ie6,firefox2.0.0.7测试通过
 6 //         控制显示
 7  /**//*  
 8      功能:修改 window.setTimeout,使之可以传递参数和对象参数  
 9      使用方法: setTimeout(回调函数,时间,参数1,,参数n)  
10  */  
11  var __sto = setTimeout;   
12  window.setTimeout = function(callback,timeout,param){//由于与其他如dropdownlist调用的setTimeout函数冲突,增加参数判断,否则会出错
13      if(param)
14      {
15          var args = Array.prototype.slice.call(arguments,2);   
16          var _cb = function(){   
17                 callback.apply(null,args);               
18          }  
19          __sto(_cb,timeout);   
20      }
21      else
22      {
23         __sto(callback,timeout); 
24      }
25  }   
26 /*
27 function   resize_image(img_id,limit_width,limit_height)  
28   {  
29   var   width,height;  
30   if   (img_id)  
31   {  
32   width=img_id.width;  
33   height=img_id.height;  
34   if(width/height>limit_width/limit_height)  
35     {if(width>limit_width)   img_id.width=limit_width;}    
36   else    
37     {if(height>limit_height)   img_id.height=limit_height;}  
38   }  
39   }
40   */
41   
42   function DT_image(img_id,limit_width,limit_height)
43   {
44 
45     var   width,height;  
46     if   (img_id)  
47     {  
48     width=img_id.width;  
49     height=img_id.height;  
50     if(width/height>limit_width/limit_height)  
51         {if(width>limit_width)   img_id.width=limit_width;}    
52     else    
53         {if(height>limit_height)   img_id.height=limit_height;}  
54 
55     } 
56  
57   } 
58 
59   function   resize_image(img_id,limit_width,limit_height)  
60   {
61     if(img_id)
62     {
63        var o=img_id;
64     //'+img_id+',\''+limit_width +'\',\''+ limit_height +'\'
65         img_id.style.display="none";
66       //setTimeout("DT_image(" + img_id + "," +limit_width + "," + limit_height+ ")",   20);   
67       //eval('window.setTimeout("DT_image('+o+',\''+limit_width +'\',\''+ limit_height +'\')",20)');参数不能是对象
68       window.setTimeout(DT_image,50,img_id,limit_width,limit_height);  
69           img_id.style.display="";
70     }
71   }
72 
73   
74   
75