<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>KUNKKA &#187; 原创</title>
	<atom:link href="http://www.kunkka.cn/category/%e5%8e%9f%e5%88%9b/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kunkka.cn</link>
	<description>活着就是折腾</description>
	<lastBuildDate>Tue, 01 Jun 2010 07:38:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>使用object在web中嵌入视频文件</title>
		<link>http://www.kunkka.cn/2010/02/02/how-to-embed-video/</link>
		<comments>http://www.kunkka.cn/2010/02/02/how-to-embed-video/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 09:54:52 +0000</pubDate>
		<dc:creator>kunkka</dc:creator>
				<category><![CDATA[Xhtml / Css]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[wmv]]></category>

		<guid isPermaLink="false">http://www.kunkka.cn:81/?p=287</guid>
		<description><![CDATA[
如何在web中嵌入视频文件，用什么方式嵌入既符合标准又能兼容主流浏览器？
在web中嵌入视频的方式有两种，使用古老的embed标签或者object标签，古老的embed标签是由传说中Netscape所创建，它虽然广泛存在，但依然没有被W3c收录，是不被W3c推荐的，取而代之的是object标签，object标签在未来的web应用中不仅用于视频媒体的嵌入，还包括images,text,audio,applets,Flash animations等等各式各样格式的文件，现在大多数主流浏览器也都支持object标签的很多类型调用，要测试你的浏览器支持那些object类型，可以查看 OBJECT test suite
那如何嵌入一段视频到web中(以wmv为例)，代码如下：



1
2
3
4
5
&#60;object data=&#34;xx.wmv&#34; type=&#34;video/x-ms-wmv&#34; width=&#34;320&#34; height=&#34;255&#34;&#62;
  &#60;param name=&#34;src&#34; value=&#34;xx.wmv&#34;&#62;
  &#60;param name=&#34;autoplay&#34; value=&#34;false&#34;&#62;
  &#60;param name=&#34;autoStart&#34; value=&#34;0&#34;&#62;
&#60;/object&#62;


以上这段代码可以正常运行在绝大多数浏览器中，如果你要插入其他格式的视频，你可以更改object标签的type属性，就比如你需要插入mpg格式的视频，type就应该为&#8221;video/mpeg&#8221;；avi格式相对应的type为&#8221;video/avi&#8221;
但在嵌入QuickTime文件时，IE7以下版本和标准浏览器还有分歧，它需要一个非标准的classid属性值，一个标识去加载一个相关联activeX，详细查看Bye Bye Embed。解决方法如下：


1
2
3
4
5
6
7
8
9
10
11
12
13
&#60;object classid=&#34;clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B&#34;
        codebase=&#34;http://www.apple.com/qtactivex/qtplugin.cab&#34;
        width=&#34;320&#34; height=&#34;255&#34;&#62;
  &#60;param name=&#34;src&#34; value=&#34;data/test.mov&#34; &#62;
  &#60;param name=&#34;controller&#34; value=&#34;true&#34; &#62;
  &#60;param name=&#34;autoplay&#34; value=&#34;false&#34;&#62;
 [...]]]></description>
			<content:encoded><![CDATA[<div style="padding-bottom:1em;text-align:center"><img src="/images/embed-video.png" alt="使用object在web中嵌入视频文件" title="使用object在web中嵌入视频文件"></div>
<p>如何在web中嵌入视频文件，用什么方式嵌入既符合标准又能兼容主流浏览器？</p>
<p>在web中嵌入视频的方式有两种，使用古老的embed标签或者object标签，古老的embed标签是由传说中Netscape所创建，它虽然广泛存在，但依然没有被W3c收录，是不被W3c推荐的，取而代之的是<a href="http://www.w3.org/TR/REC-html40/struct/objects.html" title="">object</a>标签，object标签在未来的web应用中不仅用于视频媒体的嵌入，还包括images,text,audio,applets,Flash animations等等各式各样格式的文件，现在大多数主流浏览器也都支持object标签的很多类型调用，要测试你的浏览器支持那些object类型，可以查看 <a href="http://www.student.oulu.fi/~sairwas/object-test/" title="">OBJECT test suite</a></p>
<p>那如何嵌入一段视频到web中(以wmv为例)，代码如下：</p>
<p><span id="more-287"></span></p>
<div>

<div class="wp_codebox"><table><tr id="p2874"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p287code4"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>object data<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;xx.wmv&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;video/x-ms-wmv&quot;</span> width<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;320&quot;</span> height<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;255&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;src&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;xx.wmv&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;autoplay&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;false&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;autoStart&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>object<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</div>
<p>以上这段代码可以正常运行在绝大多数浏览器中，如果你要插入其他格式的视频，你可以更改object标签的type属性，就比如你需要插入mpg格式的视频，type就应该为&#8221;video/mpeg&#8221;；avi格式相对应的type为&#8221;video/avi&#8221;</p>
<p>但在嵌入QuickTime文件时，IE7以下版本和标准浏览器还有分歧，它需要一个非标准的classid属性值，一个标识去加载一个相关联activeX，详细查看<a href="http://www.alistapart.com/articles/byebyeembed/" title="">Bye Bye Embed</a>。解决方法如下：</p>
<div>

<div class="wp_codebox"><table><tr id="p2875"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p287code5"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>object classid<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B&quot;</span>
        codebase<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://www.apple.com/qtactivex/qtplugin.cab&quot;</span>
        width<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;320&quot;</span> height<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;255&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;src&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;data/test.mov&quot;</span> <span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;controller&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;true&quot;</span> <span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;autoplay&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;false&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;!--</span><span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">if</span> gte IE <span style="color: #CC0000;">7</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span> <span style="color: #339933;">&lt;!--&gt;</span>
  <span style="color: #339933;">&lt;</span>object type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;video/quicktime&quot;</span> data<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;data/test.mov&quot;</span> width<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;320&quot;</span> height<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;255&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;controller&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;true&quot;</span> <span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;autoplay&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;false&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>object<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;!--&lt;!</span><span style="color: #009900;">&#91;</span>endif<span style="color: #009900;">&#93;</span><span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;/</span>object<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</div>
<p>在实际应用中，如果我按标准方式插入一个wmv视频到IE中，播放器需要等待wmv文件完全载入成功后才会显现出来（非流媒体播放），也就是说视频没有载入完成的时候，是不会出现播放界面的，这样对于k数比较大的视频文件，就是个悲剧。但经过尝试如果去掉object的data属性，只是使用&lt;param name=&#8221;src&#8221; value=&#8221;xx.wmv&#8221;&gt;来调用wmv文件，不仅IE正常了，而且其他主流浏览器也能正常播放&#8230;&#8230; 最终代码如下：</p>
<div>

<div class="wp_codebox"><table><tr id="p2876"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p287code6"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>object type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;video/x-ms-wmv&quot;</span> width<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;320&quot;</span> height<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;255&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;src&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;xx.wmv&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;autoplay&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;false&quot;</span><span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;autoStart&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>object<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</div>
]]></content:encoded>
			<wfw:commentRss>http://www.kunkka.cn/2010/02/02/how-to-embed-video/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>浅谈javascript的分号</title>
		<link>http://www.kunkka.cn/2009/12/03/javascript-automatic-semicolon-insertion/</link>
		<comments>http://www.kunkka.cn/2009/12/03/javascript-automatic-semicolon-insertion/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 13:39:05 +0000</pubDate>
		<dc:creator>kunkka</dc:creator>
				<category><![CDATA[javascript / Dom]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[Automatic]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Semicolon Insertion]]></category>

		<guid isPermaLink="false">http://www.kunkka.cn:81/?p=195</guid>
		<description><![CDATA[javascript的分号代表语句的结束符，但由于javascript具有分号自动插入规则，所以它是一个十分容易让人模糊的东西，在一般情况下，一个换行就会产生一个分号，但实际情况却不然，也就是说在javascript中换行可能产生分号，也可能不产生，是否自动插入分号，主要看上下行。所以即使是经验丰富的程序员，有时候也会头大。
在ECMAScript中对分号自动插入规则也有相应的解释：空语句，变量语句，表达式语句，do-while 语句，continue 语句，break 语句，return 语句，以及 throw 语句，这些确定的ECMAScript语句必须以分号结束。这些分号可以总是明确地出现在源代码文本中。为方便起见，在特定的情况下，源代码文本中的这些分号可以被省略。也就是说这些语句的结尾是不需要硬性的输入分号结尾，javascript会自动插入语句结束处。



想了解详细的ECMAScript分号自动插入规则可以查看以下链接：


原文
中文翻译



实践出真理，看一下下面这些例子，就明白，分号自动插入不是那么好让人捉摸的。稍微不注意就会让你头大。
return引起的血案

function test&#40;&#41;&#123;
   var a = 1;
   var b = 2;
   return //会自动插入分号
       &#40;
         a+b
       &#41;
&#125;;
alert&#40;test&#40;&#41;&#41;;

一个返回a+b值的函数，初看没任何问题，但运行alert的结果却是undefined。根据分号的自动插入规则，return 语句后面如果有换行就会自动插入分号，没有返回值也就比较好理解了。如果需要换行的话，可以这样：

function test&#40;&#41;&#123;
   var a = 1;
 [...]]]></description>
			<content:encoded><![CDATA[<p>javascript的分号代表语句的结束符，但由于javascript具有分号自动插入规则，所以它是一个十分容易让人模糊的东西，在一般情况下，一个换行就会产生一个分号，但实际情况却不然，也就是说在javascript中换行可能产生分号，也可能不产生，是否自动插入分号，主要看上下行。所以即使是经验丰富的程序员，有时候也会头大。</p>
<p>在<a href="http://bclary.com/2004/11/07/" title="查看ECMAScript文档">ECMAScript</a>中对分号自动插入规则也有相应的解释：<span style="text-decoration: underline; ">空语句，变量语句，表达式语句，do-while 语句，continue 语句，break 语句，return 语句，以及 throw 语句，这些确定的ECMAScript语句必须以分号结束。这些分号可以总是明确地出现在源代码文本中。为方便起见，在特定的情况下，源代码文本中的这些分号可以被省略。</span>也就是说这些语句的结尾是不需要硬性的输入分号结尾，javascript会自动插入语句结束处。
</p>
<p><span id="more-195"></span></p>
<dl>
<dt>想了解详细的ECMAScript分号自动插入规则可以查看以下链接：</dt>
<dd>
<ul>
<li><a href="http://bclary.com/2004/11/07/#a-7.9" title="查看详细">原文</a></li>
<li><a href="http://let-in.blogspot.com/2007/05/ecma-26279-automatic-semicolon.html" title="查看详细">中文翻译</a></li>
</ul>
</dd>
</dl>
<p>实践出真理，看一下下面这些例子，就明白，分号自动插入不是那么好让人捉摸的。稍微不注意就会让你头大。</p>
<p><b>return引起的血案</b></p>

<div class="wp_codebox"><table><tr id="p19511"><td class="code" id="p195code11"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> b <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #006600; font-style: italic;">//会自动插入分号</span>
       <span style="color: #009900;">&#40;</span>
         a<span style="color: #339933;">+</span>b
       <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>一个返回a+b值的函数，初看没任何问题，但运行alert的结果却是undefined。根据分号的自动插入规则，return 语句后面如果有换行就会自动插入分号，没有返回值也就比较好理解了。如果需要换行的话，可以这样：</p>

<div class="wp_codebox"><table><tr id="p19512"><td class="code" id="p195code12"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> a <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> b <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span> 
           a<span style="color: #339933;">+</span>b
          <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><b>两个闭包引起的血案</b></p>

<div class="wp_codebox"><table><tr id="p19513"><td class="code" id="p195code13"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> a<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">//不会自动插入分号</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> b<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>很诡异，解释不了，谁能告诉我～</p>
<p><b>for语句头中的两个分号，不自动插入分号</b></p>

<div class="wp_codebox"><table><tr id="p19514"><td class="code" id="p195code14"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> a<span style="color: #339933;">=</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span>b<span style="color: #339933;">=</span><span style="color: #CC0000;">10</span> <span style="color: #006600; font-style: italic;">//不会自动插入分号</span>
         a<span style="color: #339933;">&lt;</span>b <span style="color: #006600; font-style: italic;">//不会自动插入分号</span>
         a<span style="color: #339933;">++</span> 
   <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>ECMAScript对以上也有解释：将分号解释为空语句和在for语句中的()中不自动插入分号是特例，是不属于自动插入规则管辖的。</p>
<p>javascript虽然是弱类型语言，ECMAScript的分号自动插入规则也让人难以理解透彻。但养成良好的代码书写习惯，手动插入分号，养成习惯，就能避免这些问题，同时会在程序调试，代码的阅读上对自己对他人都有不小的帮助。</p>
<p>同时ECMAScript还给程序员一些忠告：</p>
<ul>
<li>++ 或 &#8212; 应和其操作数出现在同一行。</li>
<li>return 或 throw 语句中的表达式应和return 或 throw 出现在同一行。</li>
<li>break 或 continue 语句中的标签应和break 或 continue 出现在同一行。</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.kunkka.cn/2009/12/03/javascript-automatic-semicolon-insertion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Amazing ImageSwitch</title>
		<link>http://www.kunkka.cn/2009/11/24/amazing-imageswitch/</link>
		<comments>http://www.kunkka.cn/2009/11/24/amazing-imageswitch/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 09:54:33 +0000</pubDate>
		<dc:creator>kunkka</dc:creator>
				<category><![CDATA[Image]]></category>
		<category><![CDATA[javascript / Dom]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[ImageSwitch]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.kunkka.cn:81/?p=167</guid>
		<description><![CDATA[
查看Demo： Demo-1&#160;&#160;Demo-2&#160;&#160;下载源文件
amazing ImageSwitch是一个图片切换脚本，形式上类似于大多数图片切换，只是在切换效果上加了些创新。这个脚本是四个月前写的，期间也有不断地修改和完善。也不知道取个什么名字好，就暂叫amazing ImageSwitch吧 。

amazing ImageSwitch的实现需要点创意，难点在于图片的分割上，其实原理是比较简单的，就好比打碎鸡蛋在组合的过程，首先你需要把图片切割成几块，然后再将它拼接成一个完整的图片才能实现其他动画。但要真正完成图片的分割，js还实现不了，但变通一下将图片转换成背景，利用一下CSS Sprites呢，靠谱。以下是主要思路：


根据图片的宽高计算出切割块的数量和宽高（原图的宽度 = 切割快的数量 * 切割块的宽；高度计算同上）
利用DOM依次动态循环插入切割块到相应的位置。并利用css进行定位排列。
获取图片的src地址，作为背景图片备用，然后使用CSS Sprites技术，将背景定位到相对应的切割快，让其组成一个完整的图片。

当然以上说所只是大概的原理，具体实现还有很多细节上的技术需要考虑，了解详细请查看源代码。
ps：前几天在蓝色上看到一同行做了个类似的效果，详细可查看他的“奇淫技巧之图片切割”一文。声明一下哦，我可没有借鉴抄袭的嫌疑，你可以查看源代码，js的封装和写法都是完全出自不同人的手。只能说实属巧合了，呵呵。原理都差不多，多动动脑子就能想写好玩的东西。
]]></description>
			<content:encoded><![CDATA[<p><a href="/demo/amazing/demo-01.html" title="Demo-1"><img src="/wp-content/uploads/2009/11/amazing.jpg" alt="查看Demo" title="查看Demo"></a></p>
<p><b>查看Demo：</b> <a href="/demo/amazing/demo-01.html" title="Demo-1">Demo-1</a>&nbsp;&nbsp;<a href="/demo/amazing/demo-02.html" title="Demo-1">Demo-2</a>&nbsp;&nbsp;<a href="/demo/amazing/amazing.rar" title="下载源文件">下载源文件</a></p>
<p><a href="/demo/amazing/demo-01.html" title="demo">amazing ImageSwitch</a>是一个图片切换脚本，形式上类似于大多数图片切换，只是在切换效果上加了些创新。这个脚本是四个月前写的，期间也有不断地修改和完善。也不知道取个什么名字好，就暂叫<a href="/demo/amazing/demo-01.html" title="demo">amazing ImageSwitch</a>吧 。</p>
<p><span id="more-167"></span></p>
<p><a href="/demo/amazing/demo-01.html" title="demo">amazing ImageSwitch</a>的实现需要点创意，难点在于图片的分割上，其实原理是比较简单的，就好比打碎鸡蛋在组合的过程，首先你需要把图片切割成几块，然后再将它拼接成一个完整的图片才能实现其他动画。但要真正完成图片的分割，js还实现不了，但变通一下将图片转换成背景，利用一下CSS Sprites呢，靠谱。以下是主要思路：</p>
<p><!-- more --></p>
<ul>
<li>根据图片的宽高计算出切割块的数量和宽高（原图的宽度 = 切割快的数量 * 切割块的宽；高度计算同上）</li>
<li>利用DOM依次动态循环插入切割块到相应的位置。并利用css进行定位排列。</li>
<li>获取图片的src地址，作为背景图片备用，然后使用<a href="http://www.alistapart.com/articles/sprites" title="CSS Sprites">CSS Sprites</a>技术，将背景定位到相对应的切割快，让其组成一个完整的图片。</li>
</ul>
<p>当然以上说所只是大概的原理，具体实现还有很多细节上的技术需要考虑，了解详细请查看<a href="/demo/amazing/amazing.rar" title="下载源文件">源代码</a>。</p>
<p>ps：前几天在蓝色上看到一同行做了个类似的效果，详细可查看他的“<a href="http://cnwander.com/blog/?p=13">奇淫技巧之图片切割”</a>一文。声明一下哦，我可没有借鉴抄袭的嫌疑，你可以查看源代码，js的封装和写法都是完全出自不同人的手。只能说实属巧合了，呵呵。原理都差不多，多动动脑子就能想写好玩的东西。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunkka.cn/2009/11/24/amazing-imageswitch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>简单的ToolTip</title>
		<link>http://www.kunkka.cn/2009/11/17/simple-tooltip/</link>
		<comments>http://www.kunkka.cn/2009/11/17/simple-tooltip/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 06:40:25 +0000</pubDate>
		<dc:creator>kunkka</dc:creator>
				<category><![CDATA[ToolTip]]></category>
		<category><![CDATA[javascript / Dom]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.kunkka.cn:81/?p=163</guid>
		<description><![CDATA[一个简单的ToolTip，用于替换浏览器默认的提示框，适用于任何HTML元素，想要显示ToolTip，只需要在相应的html元素上添加title，或者在图片上添加alt标签。
详细查看 Demo 及其源代码
]]></description>
			<content:encoded><![CDATA[<p>一个简单的<a href="/demo/toolTip.html" title="ToolTip Demo">ToolTip</a>，用于替换浏览器默认的提示框，适用于任何HTML元素，想要显示ToolTip，只需要在相应的html元素上添加title，或者在图片上添加alt标签。</p>
<p>详细查看 <a href="/demo/toolTip.html" title="ToolTip Demo">Demo</a> 及其源代码</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunkka.cn/2009/11/17/simple-tooltip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>自家用的&#8217;popUp&#8217;</title>
		<link>http://www.kunkka.cn/2009/07/13/my-popup/</link>
		<comments>http://www.kunkka.cn/2009/07/13/my-popup/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 06:44:57 +0000</pubDate>
		<dc:creator>kunkka</dc:creator>
				<category><![CDATA[javascript / Dom]]></category>
		<category><![CDATA[popUp]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://308739.ctc-us1-g5.dns.com.cn/?p=64</guid>
		<description><![CDATA[发布一个自家用的&#8217;popUp&#8217;，详细查看 Demo。

工作这几年，如果要说什么javasrcipt交互效果做的最多，弹出框口算一个了。
现在流行的&#8217;popUp&#8217;也是非常多。有好有烂，优秀的比如： Lightbox、ThickBox、Facebox、multibox&#8230;. 以前一直是用ThickBox，至于为什么要自己写一个&#8216;popUp&#8217;主要也是考虑到自己工作的需求和利于扩展，我也不喜欢仅仅为了一个popUp效果就调用一个库，这样对于K数要求严格的网站，无疑是个比较大的负担。于是就自己琢磨了一个  
有用得到的同学可以在Demo页面下载，如果有发现BUG，请留言给我，谢谢！
]]></description>
			<content:encoded><![CDATA[<p>发布一个自家用的&#8217;popUp&#8217;，详细查看 <a href="/demo/pop/pop.html" title="">Demo</a>。</p>
<div style="text-align: center;margin:0 0 1em 0 "><a href="/demo/pop/pop.html" title="自家用的'popUp'" class="nostyle"><img src="/images/pop_p.jpg"  alt="自家用的'popUp'" class="img_wrap"></a></div>
<p>工作这几年，如果要说什么javasrcipt交互效果做的最多，弹出框口算一个了。</p>
<p>现在流行的&#8217;popUp&#8217;也是非常多。有好有烂，优秀的比如： <a href="http://leandrovieira.com/projects/jquery/lightbox/" title="Lightbox">Lightbox</a>、<a href="http://jquery.com/demo/thickbox/" title="ThickBox">ThickBox</a>、<a href="http://famspam.com/facebox" title="Facebox">Facebox</a>、<a href="http://www.phatfusion.net/multibox/" title="multibox">multibox</a>&#8230;. 以前一直是用<a href="http://jquery.com/demo/thickbox/" title="ThickBox">ThickBox</a>，至于为什么要自己写一个<a href="/demo/pop/pop.html" title="">&#8216;popUp&#8217;</a>主要也是考虑到自己工作的需求和利于扩展，我也不喜欢仅仅为了一个popUp效果就调用一个库，这样对于K数要求严格的网站，无疑是个比较大的负担。于是就自己琢磨了一个 <img src='http://www.kunkka.cn/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>有用得到的同学可以在<a href="/demo/pop/pop.html" title="">Demo</a>页面下载，如果有发现BUG，请留言给我，谢谢！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunkka.cn/2009/07/13/my-popup/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>如何检测IE8</title>
		<link>http://www.kunkka.cn/2009/06/18/how-to-detect-ie8/</link>
		<comments>http://www.kunkka.cn/2009/06/18/how-to-detect-ie8/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 10:38:44 +0000</pubDate>
		<dc:creator>kunkka</dc:creator>
				<category><![CDATA[javascript / Dom]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[IE8]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://308739.ctc-us1-g5.dns.com.cn/?p=26</guid>
		<description><![CDATA[     
单纯从检测浏览器的版本来说， userAgent对IE8已经不再可靠，原因是IE8加入了兼容性视图功能，导致IE8出现多个userAgent。详细查看gracecode的《由IE8 User-Agent 更新想到的》一文
在ie8下分别用三种”浏览器模式&#8221;运行以下代码

    alert&#40;navigator.appVersion&#41;

我在Vista下运行以上代码的结果如下：
  
可以看出除了IE版本号不一样以外，Trident标识也有区别
那么如何判断IE8，办法还是有的&#8230;&#8230;
 
功能检测
检测浏览器是否支持IE8特有的WebSlices、Accelerator、Visual Search 功能

function isIE8&#40;&#41;&#123;
  return typeof &#40;window.external.AddToFavoritesBar&#41; != &#34;undefined&#34; 
         &#124;&#124; typeof &#40;window.external.AddService&#41; != &#34;undefined&#34;
         &#124;&#124; typeof &#40;window.external.AddService&#41; != &#34;undefined&#34;
&#125;
try&#123;
  if&#40;isIE8&#40;&#41;&#41;
  [...]]]></description>
			<content:encoded><![CDATA[<p>     <img style="float:left;margin:0 20px 10px 0" src="/images/test_IE8.png" alt="" width="100" height="100px"/>
<p>单纯从检测浏览器的版本来说， <a href="http://www.w3school.com.cn/htmldom/prop_nav_useragent.asp" title="什么是userAgent">userAgent</a>对IE8已经不再可靠，原因是IE8加入了<a href="http://blogs.msdn.com/ie/archive/2008/08/27/introducing-compatibility-view.aspx" title="什么是IE8兼容性试图功能">兼容性视图功能</a>，导致IE8出现多个userAgent。<br />详细查看gracecode的<a href="http://www.gracecode.com/archives/2717/" title="查看详细">《由IE8 User-Agent 更新想到的》</a>一文</p>
<p>在ie8下分别用三种”浏览器模式&#8221;运行以下代码</p>

<div class="wp_codebox"><table><tr id="p2619"><td class="code" id="p26code19"><pre class="javascript" style="font-family:monospace;">    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">appVersion</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>我在Vista下运行以上代码的结果如下：</p>
<p>  <img src="/images/IE8_test.gif" class="img_wrap"/></p>
<p>可以看出除了IE版本号不一样以外，<a href="http://en.wikipedia.org/wiki/Trident_(layout_engine)" title="了解Trident">Trident</a>标识也有区别</p>
<p>那么如何判断IE8，办法还是有的&#8230;&#8230;</p>
<p> <span id="more-26"></span></p>
<h4>功能检测</h4>
<p>检测浏览器是否支持IE8特有的WebSlices、Accelerator、Visual Search 功能</p>

<div class="wp_codebox"><table><tr id="p2620"><td class="code" id="p26code20"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> isIE8<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">external</span>.<span style="color: #660066;">AddToFavoritesBar</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;undefined&quot;</span> 
         <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">external</span>.<span style="color: #660066;">AddService</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;undefined&quot;</span>
         <span style="color: #339933;">||</span> <span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">external</span>.<span style="color: #660066;">AddService</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;undefined&quot;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>isIE8<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'IE8'</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000066; font-weight: bold;">else</span> 
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'非IE8浏览器'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
 <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'非IE8浏览器'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>对象检测</h4>
<p>利用IE8的<a href="http://msdn.microsoft.com/zh-cn/library/cc288060(en-us,VS.85).aspx" title="关于XDomainRequest">XDomainRequest</a>对象检测（推荐）</p>

<div class="wp_codebox"><table><tr id="p2621"><td class="code" id="p26code21"><pre class="javascript" style="font-family:monospace;">   <span style="color: #003366; font-weight: bold;">var</span> isIE8 <span style="color: #339933;">=</span> <span style="color: #339933;">!!</span>window.<span style="color: #660066;">XDomainRequest</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>以上两种解决方案现在是可以解决IE8的判断问题，但是也只是向后兼容的解决方案，如果IE发布新的浏览器，以上的方法将不再可靠，到时候还需要userAgent和特性检测相结合的方法。IE真是个让人很头疼的东西～。</p>
<h4>延伸</h4>
<p>IE,FF,safari,chrome,opera主流浏览器的检测</p>

<div class="wp_codebox"><table><tr id="p2622"><td class="code" id="p26code22"><pre class="javascript" style="font-family:monospace;">   ie <span style="color: #339933;">=</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\v</span>'</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'v'</span><span style="color: #339933;">;</span>   
   ie <span style="color: #339933;">=</span> <span style="color: #339933;">!!</span>top.<span style="color: #660066;">execScript</span><span style="color: #339933;">;</span>   
   ie <span style="color: #339933;">=</span> <span style="color: #006600; font-style: italic;">/*@cc_on!@*/</span><span style="color: #339933;">!</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>   
   ie8 <span style="color: #339933;">=</span> <span style="color: #339933;">!!</span>window.<span style="color: #660066;">XDomainRequest</span><span style="color: #339933;">;</span>   
   IEVersion <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #006600; font-style: italic;">/*@cc_on+ScriptEngineMajorVersion()@*/</span><span style="color: #339933;">;</span>   
   ff <span style="color: #339933;">=</span> <span style="color: #339933;">/</span>a<span style="color: #339933;">/</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'a'</span><span style="color: #339933;">;</span>   
   ff3 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span>  x<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'x'</span><span style="color: #339933;">;</span>   
   ff2 <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> x<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">6</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">'x'</span><span style="color: #339933;">;</span>   
   safari<span style="color: #339933;">=</span><span style="color: #009966; font-style: italic;">/a/</span>.__proto__<span style="color: #339933;">==</span><span style="color: #3366CC;">'//'</span><span style="color: #339933;">;</span>   
   chrome<span style="color: #339933;">=</span><span style="color: #009966; font-style: italic;">/source/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/a/</span>.<span style="color: #660066;">toString</span><span style="color: #339933;">+</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
   opera<span style="color: #339933;">=</span><span style="color: #009966; font-style: italic;">/^function \(/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">sort</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.kunkka.cn/2009/06/18/how-to-detect-ie8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>非侵入式 &#8220;images loading&#8221;</title>
		<link>http://www.kunkka.cn/2009/06/15/images-loading/</link>
		<comments>http://www.kunkka.cn/2009/06/15/images-loading/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 07:15:36 +0000</pubDate>
		<dc:creator>kunkka</dc:creator>
				<category><![CDATA[javascript / Dom]]></category>
		<category><![CDATA[原创]]></category>
		<category><![CDATA[images loading]]></category>

		<guid isPermaLink="false">http://308739.ctc-us1-g5.dns.com.cn/?p=1</guid>
		<description><![CDATA[    
当我们在浏览一个网站的时候，由于受到网速(或者带宽)的影响，大幅的或高质量图片的载入速度将显得非常慢。虽然你可以通过压缩图片的尺寸，或者通过服务器端的技术来优化，但也无法从根本上解决问题，给用户好的浏览体验。
&#8220;images loading&#8221;是个不错的增强用户体验的方法。要判断图片是否载入成功，常用的方法是image的onload方法，或者通过image的complete属性来判断图片的当前载入状态，
下面就以上两种方法分别给出解决方案

onload &#8211; Demo
complete &#8211; Demo



//使用'onload'方法的解决方案
function addLoadEvent&#40;loadEvent,waitForImages&#41; &#123;
    if&#40;waitForImages&#41; &#123;
        return addEvent&#40;window, 'load', loadEvent&#41;;
    &#125;
    var init = function&#40;&#41; &#123;
        if &#40;arguments.callee.done&#41; return;
      [...]]]></description>
			<content:encoded><![CDATA[<p>    <img style="float:left;margin:0 20px 10px 0" src="/images/img_loading.png" alt="" width="100" height="100px"/></p>
<p>当我们在浏览一个网站的时候，由于受到网速(或者带宽)的影响，大幅的或高质量图片的载入速度将显得非常慢。虽然你可以通过压缩图片的尺寸，或者通过服务器端的技术来优化，但也无法从根本上解决问题，给用户好的浏览体验。</p>
<p>&#8220;images loading&#8221;是个不错的增强用户体验的方法。要判断图片是否载入成功，常用的方法是image的<a href="http://www.w3school.com.cn/htmldom/event_onload.asp" title="">onload</a>方法，或者通过image的<a href="http://www.w3school.com.cn/htmldom/prop_img_complete.asp" title="">complete</a>属性来判断图片的当前载入状态，</p>
<p>下面就以上两种方法分别给出解决方案</p>
<ul>
<li><span class="gray">onload</span> &#8211;<a href="/demo/images-loading/onload.html" target="blank"> Demo</a></li>
<li><span class="gray">complete</span> &#8211;<a href="/demo/images-loading/complete.html" target="blank"> Demo</a></li>
</ul>
<p><span id="more-1"></span></p>

<div class="wp_codebox"><table><tr id="p125"><td class="code" id="p1code25"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//使用'onload'方法的解决方案</span>
<span style="color: #003366; font-weight: bold;">function</span> addLoadEvent<span style="color: #009900;">&#40;</span>loadEvent<span style="color: #339933;">,</span>waitForImages<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>waitForImages<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> addEvent<span style="color: #009900;">&#40;</span>window<span style="color: #339933;">,</span> <span style="color: #3366CC;">'load'</span><span style="color: #339933;">,</span> loadEvent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #003366; font-weight: bold;">var</span> init <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>arguments.<span style="color: #660066;">callee</span>.<span style="color: #660066;">done</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
        arguments.<span style="color: #660066;">callee</span>.<span style="color: #660066;">done</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        loadEvent.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>document<span style="color: #339933;">,</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        document.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;DOMContentLoaded&quot;</span><span style="color: #339933;">,</span> init<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/WebKit/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">userAgent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> _timer <span style="color: #339933;">=</span> setInterval<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/loaded|complete/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">readyState</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                clearInterval<span style="color: #009900;">&#40;</span>_timer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #009966; font-style: italic;">/*@cc_on @*/</span>
    <span style="color: #006600; font-style: italic;">/*@if (@_win32)
    document.write(&quot;&lt;script id=__ie_onload defer src=javascript:void(0)&gt;&lt;\/script&gt;&quot;);
    var script = document.getElementById(&quot;__ie_onload&quot;);
    script.onreadystatechange = function() {
        if (this.readyState == &quot;complete&quot;) {
            init();
        }
    };
    /*@end @*/</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> photoShow<span style="color: #009900;">&#40;</span>o<span style="color: #339933;">,</span>parm<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">o</span> <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgs</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">o</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">loadImg</span> <span style="color: #339933;">=</span> parm.<span style="color: #660066;">loadImg</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
photoShow.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
   init<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #003366; font-weight: bold;">var</span> _this <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> length <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgs</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
     <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>length <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgs</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">complete</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
         <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgs</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span>
         <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgs</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">background</span>  <span style="color: #339933;">=</span> <span style="color: #3366CC;">'url('</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">loadImg</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">') no-repeat center'</span><span style="color: #339933;">;</span>
         <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgs</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> _this.<span style="color: #660066;">showPic</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
   showPic <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      o.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">background</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span>
      o.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
      <span style="color: #003366; font-weight: bold;">var</span> _this <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span> <span style="color: #339933;">,</span> count <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>count <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
        count <span style="color: #339933;">+=</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
        _this.<span style="color: #660066;">setOpacity</span><span style="color: #009900;">&#40;</span>o<span style="color: #339933;">,</span>count<span style="color: #009900;">&#41;</span>
        setTimeout<span style="color: #009900;">&#40;</span> arguments.<span style="color: #660066;">callee</span> <span style="color: #339933;">,</span> <span style="color: #3366CC;">'10'</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
   setOpacity <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> elem<span style="color: #339933;">,</span> level <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> elem.<span style="color: #660066;">filters</span> <span style="color: #009900;">&#41;</span>
           elem.<span style="color: #660066;">style</span>.<span style="color: #660066;">filter</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'alpha(opacity='</span> <span style="color: #339933;">+</span> level <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #339933;">;</span>
       <span style="color: #000066; font-weight: bold;">else</span>
           elem.<span style="color: #660066;">style</span>.<span style="color: #660066;">opacity</span> <span style="color: #339933;">=</span> level <span style="color: #339933;">/</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
addLoadEvent<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">new</span> photoShow<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'photos01'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>loadImg<span style="color: #339933;">:</span><span style="color: #3366CC;">'31-0.gif'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #003366; font-weight: bold;">new</span> photoShow<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'photos02'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>loadImg<span style="color: #339933;">:</span><span style="color: #3366CC;">'32-0.gif'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p126"><td class="code" id="p1code26"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//使用'complete'属性的解决方案</span>
<span style="color: #003366; font-weight: bold;">function</span> addLoadEvent<span style="color: #009900;">&#40;</span>loadEvent<span style="color: #339933;">,</span>waitForImages<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>waitForImages<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000066; font-weight: bold;">return</span> addEvent<span style="color: #009900;">&#40;</span>window<span style="color: #339933;">,</span> <span style="color: #3366CC;">'load'</span><span style="color: #339933;">,</span> loadEvent<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #003366; font-weight: bold;">var</span> init <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>arguments.<span style="color: #660066;">callee</span>.<span style="color: #660066;">done</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
         arguments.<span style="color: #660066;">callee</span>.<span style="color: #660066;">done</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
         loadEvent.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>document<span style="color: #339933;">,</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
     <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         document.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;DOMContentLoaded&quot;</span><span style="color: #339933;">,</span> init<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/WebKit/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">userAgent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #003366; font-weight: bold;">var</span> _timer <span style="color: #339933;">=</span> setInterval<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/loaded|complete/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">readyState</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                 clearInterval<span style="color: #009900;">&#40;</span>_timer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                 init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
             <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #009966; font-style: italic;">/*@cc_on @*/</span>
     <span style="color: #006600; font-style: italic;">/*@if (@_win32)
     document.write(&quot;&lt;script id=__ie_onload defer src=javascript:void(0)&gt;&lt;\/script&gt;&quot;);
     var script = document.getElementById(&quot;__ie_onload&quot;);
     script.onreadystatechange = function() {
         if (this.readyState == &quot;complete&quot;) {
             init();
         }
     };
     /*@end @*/</span>
     <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> 
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> photoShow<span style="color: #009900;">&#40;</span>o<span style="color: #339933;">,</span>parm<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">o</span> <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgs</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">o</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;img&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">loadImg</span> <span style="color: #339933;">=</span> parm.<span style="color: #660066;">loadImg</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
photoShow.<span style="color: #660066;">prototype</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    init<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #003366; font-weight: bold;">var</span> length <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgs</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
      <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>length <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgs</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">complete</span><span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgs</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">background</span>  <span style="color: #339933;">=</span> <span style="color: #3366CC;">'url('</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">loadImg</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">') no-repeat center'</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgs</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">initImg</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">imgs</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    initImg <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #003366; font-weight: bold;">var</span> _this <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
       <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>o.<span style="color: #660066;">complete</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> _this.<span style="color: #660066;">showPic</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
       setTimeout<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> _this.<span style="color: #660066;">initImg</span><span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span> <span style="color: #339933;">,</span> <span style="color: #3366CC;">'10'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    showPic <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>o<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       o.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">background</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'none'</span><span style="color: #339933;">;</span>
       o.<span style="color: #660066;">style</span>.<span style="color: #660066;">display</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'block'</span><span style="color: #339933;">;</span>
       <span style="color: #003366; font-weight: bold;">var</span> _this <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span> <span style="color: #339933;">,</span> count <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
       <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>count <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
         count <span style="color: #339933;">+=</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
         _this.<span style="color: #660066;">setOpacity</span><span style="color: #009900;">&#40;</span>o<span style="color: #339933;">,</span>count<span style="color: #009900;">&#41;</span>
         setTimeout<span style="color: #009900;">&#40;</span> arguments.<span style="color: #660066;">callee</span> <span style="color: #339933;">,</span> <span style="color: #3366CC;">'10'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    setOpacity <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> elem<span style="color: #339933;">,</span> level <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> elem.<span style="color: #660066;">filters</span> <span style="color: #009900;">&#41;</span>
            elem.<span style="color: #660066;">style</span>.<span style="color: #660066;">filter</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'alpha(opacity='</span> <span style="color: #339933;">+</span> level <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">else</span>
            elem.<span style="color: #660066;">style</span>.<span style="color: #660066;">opacity</span> <span style="color: #339933;">=</span> level <span style="color: #339933;">/</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
addLoadEvent<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #003366; font-weight: bold;">new</span> photoShow<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'photos01'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>loadImg<span style="color: #339933;">:</span><span style="color: #3366CC;">'31-0.gif'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
 <span style="color: #003366; font-weight: bold;">new</span> photoShow<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'photos02'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>loadImg<span style="color: #339933;">:</span><span style="color: #3366CC;">'32-0.gif'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>上面用到了<span class="gray">addLoadEvent</span>方法，用于在页面DOM载入完成后立即执行相应的函数，</p>
<p>以上两段代码从性能上讲显然是使用<span class="gray">onload</span>方法更好点，<span class="gray">onload</span>是当图像装载完毕时调用的事件句柄。而<span class="gray">complete</span>属性是返回浏览器是否已完成对图像的加载,是一种当前状态，返回的值是布尔值。结合此列来讲，要判断images是否加载完成，就要反复的判断image.complete是否为真，这样就要用到setTimeout或者setInterval函数，这也将增大浏览器的开销。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kunkka.cn/2009/06/15/images-loading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

