<?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>Hiro技术站 &#187; 前端工程</title>
	<atom:link href="http://www.ihiro.org/category/front-end-engineering/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ihiro.org</link>
	<description></description>
	<lastBuildDate>Fri, 06 Jan 2012 07:58:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>XSLT:通过间隔符获取英文名的First Name和Last Name</title>
		<link>http://www.ihiro.org/xslt-get-the-first-last-name</link>
		<comments>http://www.ihiro.org/xslt-get-the-first-last-name#comments</comments>
		<pubDate>Fri, 06 Jan 2012 07:51:55 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[XML、XSLT]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSLT]]></category>
		<category><![CDATA[前端工程]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1727</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2012/01/xml-xslt.png" alt="" title="xml-xslt" width="100" height="100" class="alignleft size-full wp-image-1732" />
<p>本文是工作中关于XSLT和XML一个小实例的分享。</p>
<p><strong>需求</strong>：XML抛出数据字段username,如Hiro xxx Zhang,需要通过XSLT获得First Name和Last Name，并填入到对应Form表单的字段中。</p>
<p>就XSLT来说，没有像JS中indexOf和lastIndexOf方法，所以不能够通过定位“空格”位置的方法去实现。唯一的方法只能通过“空格”反复去截取，知道剩下的字符串中没有空格。</p>
<p><strong>First Name</strong>通过截取第一个“空格”前的所有字符串：substring-before($name, ' ')。</p>
<p><strong>Lsat Name</strong>则通过递归的方法，方法截取“空格”后面的字符串，直到最后只剩下一个不含空格的字符串即可：xsl:template name="lastName"。</p>]]></description>
			<content:encoded><![CDATA[<p>本文是工作中关于XSLT和XML一个小实例的分享。</p>
<p><strong>需求</strong>：XML抛出数据字段username,如Hiro xxx Zhang,需要通过XSLT获得First Name和Last Name，并填入到对应Form表单的字段中。</p>
<p>就XSLT来说，没有像JS中indexOf和lastIndexOf方法，所以不能够通过定位“空格”位置的方法去实现。唯一的方法只能通过“空格”反复去截取，知道剩下的字符串中没有空格。</p>
<h3>1. XML数据：</h3>

<div class="wp_codebox"><table><tr id="p17271"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1727code1"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt; ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Hiro ODC Zhang<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<h3>2. XSLT代码：</h3>

<div class="wp_codebox"><table><tr id="p17272"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code" id="p1727code2"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt; ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:output</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;html&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">omit-xml-declaration</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:variable</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;xsl:value</span> -of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/xsl:variable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:variable</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;firstName&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;xsl:value</span> -of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;substring-before($name, ' ')&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/xsl:variable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:variable</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;lastName&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:call</span> -template <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;lastName&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:with</span> -param <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;xsl:value</span> -of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$name&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/xsl:with<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:call<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:variable<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        First Name: <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value</span> -of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$firstName&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;br</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        Last Name: <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value</span> -of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$lastName&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;lastName&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:choose<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:when</span> <span style="color: #000066;">test</span>=<span style="color: #ff0000;">&quot;contains($name, ' ')&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:call</span> -template <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;lastName&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:with</span> -param <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;xsl:value</span> -of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;substring-after($name, ' ')&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/xsl:with<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:call<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:when<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:otherwise<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value</span> -of <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;$name&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:otherwise<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:choose<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><strong>First Name</strong>通过截取第一个“空格”前的所有字符串：substring-before($name, &#8216; &#8216;)。</p>
<p><strong>Lsat Name</strong>则通过递归的方法，方法截取“空格”后面的字符串，直到最后只剩下一个不含空格的字符串即可：xsl:template name=”lastName”。</p>
<p><a href="http://www.ihiro.org/blog/wp-content/uploads/2012/01/TEST.zip" rel="external">下载XSLT代码文件</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li><li>2010年12月30日 -- <a href="http://www.ihiro.org/javascript-getweek-by-date" title="Javascript:根据指定日期获得星期数">Javascript:根据指定日期获得星期数</a> (23)</li><li>2010年11月25日 -- <a href="http://www.ihiro.org/css-position-hack" title="CSS:position属性定位总结">CSS:position属性定位总结</a> (28)</li><li>2010年11月22日 -- <a href="http://www.ihiro.org/text-range" title="Range:文本框选区学习笔记">Range:文本框选区学习笔记</a> (16)</li><li>2010年11月3日 -- <a href="http://www.ihiro.org/html5-pro-ebook-recommendations" title="HTML5:《Pro HTML5 Programming》英文电子书推荐">HTML5:《Pro HTML5 Programming》英文电子书推荐</a> (21)</li><li>2010年07月4日 -- <a href="http://www.ihiro.org/perforomance-best-pritices-for-web-developers" title="读书:《高性能网站建设进阶指南:Web开发者性能优化最佳实践 》">读书:《高性能网站建设进阶指南:Web开发者性能优化最佳实践 》</a> (10)</li><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/xslt-get-the-first-last-name/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>插件：Firebug扩展插件FireQuery</title>
		<link>http://www.ihiro.org/firebug-extension-firequery</link>
		<comments>http://www.ihiro.org/firebug-extension-firequery#comments</comments>
		<pubDate>Fri, 25 Nov 2011 08:21:23 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[前端工程]]></category>
		<category><![CDATA[浏览器插件]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1701</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/11/firequery.png" alt="" title="FireQuery Logo" width="100" height="100" class="alignleft size-full wp-image-1702" />
<p>之前也不知道看了哪篇文章的介绍，在火狐上装了FireQuery插件，一直没去注意它的用途。就只发现在FireBug的HTML Tab下的HTML代码层次上多了些事件代码，可以点击查看对应的绑定事件。最近的一些使用，发现了FireQuery的好处，特别是在测试动态生成DOM以及数据测试上很是方便。</p>
<p>关于FireQuery的简介和安装就不多说了，访问：<a href="http://firequery.binaryage.com/" rel="external">http://firequery.binaryage.com/</a>。</p>
<p>官方测试页面：<a href="http://firequery.binaryage.com/test" rel="external">http://firequery.binaryage.com/test</a></p>]]></description>
			<content:encoded><![CDATA[<p>之前也不知道看了哪篇文章的介绍，在火狐上装了FireQuery插件，一直没去注意它的用途。就只发现在FireBug的HTML Tab下的HTML代码层次上多了些事件代码，可以点击查看对应的绑定事件。最近的一些使用，发现了FireQuery的好处，特别是在测试动态生成DOM以及数据测试上很是方便。</p>
<p>关于FireQuery的简介和安装就不多说了，访问：<a href="http://firequery.binaryage.com/" rel="external">http://firequery.binaryage.com/</a>。</p>
<h3>1. 标签绑定事件查看</h3>
<p>打开Firebug的HTML Tab，在一些绑定了事件的HTML标签上可以看到一些事件数据：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/11/1.click-to-view-DOM.jpg" alt="" title="Click to view DOM" width="561" height="94" class="aligncenter size-full wp-image-1703" />点击后跳转到DOM Tab，可以查看对应的一些信息：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/11/2.DOM-view-e1322209489464.jpg" alt="" title="DOM view" width="600" height="233" class="aligncenter size-full wp-image-1704" /></p>
<h3>2. 查看jQuery的.data()函数添加的数据</h3>
<p>jQuery的.data()函数是用来给HTML上添加数据的，一般用在插件或数据处理上。一般情况下执行了.data()后，无法确认是否给该标签正确地绑定了数据。此时通过FireQuery就可以查看，同样支持点击后跳转到DOM Tab查看，这在给HTML标签绑定一些对象数据时非常实用。<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/11/3.view-data-and-event.jpg" alt="" title="View data" width="600" height="159" class="aligncenter size-full wp-image-1705" /></p>
<h3>3. 引入jQuery.Lint.js对页面代码测试</h3>
<p>在Console Tab的下拉菜单中启用引入，重新刷新页面后会动态地引入jQuery.Lint.js插件，此时对页面中出现的错误进行输出提示。<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/11/4.enable-Use-jQuery-Lint.jpg" alt="" title="Enable to Use jQuery.Lint" width="370" height="370" class="aligncenter size-full wp-image-1706" /><img src="http://www.ihiro.org/blog/wp-content/uploads/2011/11/5.jquery.lint_.jpg" alt="" title="jQuery.lint" width="137" height="45" class="aligncenter size-full wp-image-1707" /><img src="http://www.ihiro.org/blog/wp-content/uploads/2011/11/6.track-css-error.jpg" alt="" title="Track CSS error" width="444" height="43" class="aligncenter size-full wp-image-1708" /></p>
<p>FireQuery对于前端开发和测试来说绝对是一大助手，更多的好处还是在实际中可以体会出来。</p>
<p>官方测试页面：<a href="http://firequery.binaryage.com/test" rel="external">http://firequery.binaryage.com/test</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年10月21日 -- <a href="http://www.ihiro.org/jquery-plugin-recommended-maphighlight" title="jQuery:热区高亮maphighlight插件推荐">jQuery:热区高亮maphighlight插件推荐</a> (23)</li><li>2010年06月30日 -- <a href="http://www.ihiro.org/firebug-console-panel-function" title="Firebug:Javascript测试利器，Console面板函数详解">Firebug:Javascript测试利器，Console面板函数详解</a> (4)</li><li>2010年06月12日 -- <a href="http://www.ihiro.org/firefox-4-will-support-css3-calc-method" title="CSS:Firefox 4 将支持CSS3 calc方法">CSS:Firefox 4 将支持CSS3 calc方法</a> (18)</li><li>2010年05月21日 -- <a href="http://www.ihiro.org/dw-html5-extension" title="扩展:Adobe放出Dreamweaver CS5 HTML 5扩展包">扩展:Adobe放出Dreamweaver CS5 HTML 5扩展包</a> (16)</li><li>2010年02月24日 -- <a href="http://www.ihiro.org/javascript-news-flash-header-tips" title="Javascript:新消息闪烁标题提示代码分享">Javascript:新消息闪烁标题提示代码分享</a> (7)</li><li>2009年12月25日 -- <a href="http://www.ihiro.org/httpwatch-for-viewing-the-http-requests" title="软件:查看页面的http请求软件HttpWatch">软件:查看页面的http请求软件HttpWatch</a> (10)</li><li>2009年11月2日 -- <a href="http://www.ihiro.org/my-first-plugin-scrolltop" title="插件:我的第一个插件&#8211;简约的scrollTop滑动插件">插件:我的第一个插件&#8211;简约的scrollTop滑动插件</a> (23)</li><li>2009年08月21日 -- <a href="http://www.ihiro.org/jquery-scrolltop-plugins" title="jQuery:Scrolltop滑动插件推荐（修正注释版）">jQuery:Scrolltop滑动插件推荐（修正注释版）</a> (25)</li><li>2009年07月16日 -- <a href="http://www.ihiro.org/the-firefox-plugins-for-developers-required" title="Plugins:开发人员必备的Firefox插件（个人在用）">Plugins:开发人员必备的Firefox插件（个人在用）</a> (6)</li><li>2009年06月19日 -- <a href="http://www.ihiro.org/10-reasons-why-the-use-of-firebug" title="10个为什么使用Firebug的原因">10个为什么使用Firebug的原因</a> (5)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/firebug-extension-firequery/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Git：利用Git同步代码到Github，实现多台电脑的代码同步</title>
		<link>http://www.ihiro.org/use-git-synchronize-code-to-github</link>
		<comments>http://www.ihiro.org/use-git-synchronize-code-to-github#comments</comments>
		<pubDate>Tue, 17 May 2011 07:24:21 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[Github]]></category>
		<category><![CDATA[IDEA]]></category>
		<category><![CDATA[VCS]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1666</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/hiro_at_github.jpg" alt="" title="hiro_at_github" width="100" height="100" class="alignleft size-full wp-image-1687" />
<p>这几天工作比较清闲，就花了点时间研究了下Github上控制代码版本的事情。之前就一直想找个可以同步代码的服务，这样公司和电脑上自己研究和学习的那些东西就可以同步起来。只需要更新一下即可，而不像之前一直用U盘或者是Dropbox之类的。Github既实现了版本控制，又能同步，同时还可以分享代码，何乐而不为。</p>
<p>其实Github官方和Git官方都有很详细的教程，一步一步地做下去，都可以实现。我今天主要讲的是非Git安装目录下的代码同步以及使用IntelliJ IDEA软件分享和获取Github上的代码。</p>]]></description>
			<content:encoded><![CDATA[<p>这几天工作比较清闲，就花了点时间研究了下Github上控制代码版本的事情。之前就一直想找个可以同步代码的服务，这样公司和电脑上自己研究和学习的那些东西就可以同步起来。只需要更新一下即可，而不像之前一直用U盘或者是Dropbox之类的。Github既实现了版本控制，又能同步，同时还可以分享代码，何乐而不为。</p>
<p>其实Github官方和Git官方都有很详细的教程，一步一步地做下去，都可以实现。我今天主要讲的是非Git安装目录下的代码同步以及使用IntelliJ IDEA软件分享和获取Github上的代码。</p>
<h3>一、通过官方教程搭建环境：</h3>
<p>具体的请阅读：<a href="http://help.github.com/" rel="external">http://help.github.com/</a>，更多的Git的代码命名可以阅读：<a href="http://gitref.org/" rel="external">Git Reference</a>。基本上看完这些就对Git有了很大程度上的了解，这时候最还记录一些常用的命名笔记（推荐<a href="http://www.evernote.com/ rel="external"">Evernote</a>,支持多平台同步）。并且教程中也讲解了如何创建仓库、提交仓库的方法，请自行阅读。</p>
<p>装完后其实我纠结了很长的时间，一直找不到虚拟的Home文件夹所在地，后来发现Git在我的电脑中虚拟了一个网络目录：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/virtual_home.jpg" alt="" title="virtual_home" width="245" height="81" class="aligncenter size-full wp-image-1667" /> 也正是因为只有一个虚拟的目录，这与我原来自己的目录根本联系不上，才促发了我去找寻自选择目录分享。</p>
<p>Mac OS相关教程：<a href="http://help.github.com/mac-set-up-git/" rel="external">http://help.github.com/mac-set-up-git/</a></p>
<h3>二、自选择目录分享到Github：</h3>
<p>其实在没发现前觉得很简单，找了很多命令行都没实现。后来发现只需要在目录中右键即可，在右键的菜单里会多出一些与Git相关的菜单：(截图是已经成功提交过后的菜单的)<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/right_click.jpg" alt="" title="right_click" width="349" height="407" class="aligncenter size-full wp-image-1668" /> </p>
<ol class="ol_with_num">
<li>第一次时会有一个”Git init”的菜单，点击后机会在当前目录下创建一个”.git”隐藏文件。</li>
<li>接着右键选择”Git Add all files now”，它的意思是将所有的文件都添加到Git的提交列表中。</li>
<li>右键选择”Git commit Tool”菜单，会出现一个对话框：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/git_commit_tool_after.jpg" alt="" title="git_commit_tool_after" width="500" height="305" class="aligncenter size-full wp-image-1672" /> 在左侧会列出你上部选择的所有文件的列表，点击文件还可以查看文件中的代码。在右下角的“提交描述”框内输入该次提交的备注信息后，点击“提交”按钮即可。若未执行第二步的话，看到的界面会是：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/git_commit_tool_before.jpg" alt="" title="git_commit_tool_before" width="500" height="306" class="aligncenter size-full wp-image-1673" /> 而点击”提交“按钮则报错阻止。</li>
<li>最后一步，右键选择”Git Bash”菜单，在命令行中输入”git push origin master”后回车，等待一段时间后可以看到提交的进度百分数：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/git_push_origin_master.jpg" alt="" title="git_push_origin_master" width="418" height="163" class="aligncenter size-full wp-image-1681" /> 结束后即可访问你的Github账户，便可看到上传的代码了。</li>
</ol>
<h3>三、使用IntelliJ IDEA分享、获取Github项目：</h3>
<p><strong>首先得在IDEA中配置Git：</strong></p>
<ol class="ol_with_num">
<li>选择菜单”File &#8212; Settings”，找到”Version Control &#8212; VCSs &#8212; Git”：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/IDE_seeting_git_01.jpg" alt="" title="IDE_seeting_git_01" width="359" height="253" class="aligncenter size-full wp-image-1674" /></li>
<li>在右侧的区域中找到Git的安装目录下的Git.exe执行文件所在地：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/IDE_seeting_git_02.jpg" alt="" title="IDE_seeting_git_02" width="387" height="210" class="aligncenter size-full wp-image-1675" /> 只需修改这项，其他可以保持默认。</li>
<li>配置完成。<br />
附：查看Git分享列表可以在”Version Control”下：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/IDE_seeting_git_03.jpg" alt="" title="IDE_seeting_git_03" width="352" height="254" class="aligncenter size-full wp-image-1676" /></li>
</ol>
<p><strong>其次，配置你在Github上注册的账户：</strong></p>
<ol class="ol_with_num">
<li>选择菜单”File &#8212; Settings”，找到”IDE Settings &#8212; Github”：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/IDE_seeting_github_01.jpg" alt="" title="IDE_seeting_github_01" width="358" height="295" class="aligncenter size-full wp-image-1677" /></li>
<li>输入域名，账户和密码：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/IDE_seeting_github_02.jpg" alt="" title="IDE_seeting_github_02" width="462" height="198" class="aligncenter size-full wp-image-1678" /> 点击”Test”按钮测试连接，若链接成功会提示”Connection successful”。保存完成。</li>
</ol>
<p><strong>分享Github项目：</strong></p>
<ol class="ol_with_num">
<li>选择菜单”Version Control &#8212; Import into Version Control &#8212; Share project on Github”：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/Github_share_01.jpg" alt="" title="Github_share_01" width="500" height="274" class="aligncenter size-full wp-image-1686" /> </li>
<li>等待一段时间的验证和登陆，出现界面：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/Github_share_01.jpg" alt="" title="Github_share_01" width="500" height="274" class="aligncenter size-full wp-image-1686" /> 填写描述信息后，点击”Share”按钮即可。</li>
</ol>
<p><strong>获取Github项目：</strong></p>
<ol class="ol_with_num">
<li>选择菜单”Version Control &#8212; Checkout from Version Control &#8212; Github”：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/Github_checkout_01.jpg" alt="" title="Github_checkout_01" width="427" height="258" class="aligncenter size-full wp-image-1684" /> </li>
<li>等待一段时间的验证和登陆，出现界面：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/05/Github_checkout_02.jpg" alt="" title="Github_checkout_02" width="347" height="167" class="aligncenter size-full wp-image-1685" /> 在”Repository”下来列表中既有你自己的项目，也有你在Github网站上”Wacth”的项目，选择后，选择你存放的路径，再输入你想要的项目名称，点击”Clone”按钮，即完成获取过程。</li>
</ol>
<p class="red"><strong>附：若在公司使用IDEA分享或获取Github项目，有可能因为域的问题无法实现，具体原因未做甚久。此时可以通过命名行代替实现。</strong></p>
<h2  class="related_post_title">最热评论文章列表:</h2><ul class="related_post"><li>2009年08月5日 -- <a href="http://www.ihiro.org/my-first-theme-for-download" title="主题：我的第一个主题ihiro提供下载了">主题：我的第一个主题ihiro提供下载了</a> (101)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2009年12月31日 -- <a href="http://www.ihiro.org/plugins-garden" title="插件专区">插件专区</a> (50)</li><li>2011年01月11日 -- <a href="http://www.ihiro.org/intellij-idea" title="软件:使用IntelliJ IDEA，高效前端开发">软件:使用IntelliJ IDEA，高效前端开发</a> (50)</li><li>2009年08月7日 -- <a href="http://www.ihiro.org/abandon-google-and-baidu-then-alimama" title="网赚:抛弃谷歌、百度，转战阿里妈妈">网赚:抛弃谷歌、百度，转战阿里妈妈</a> (47)</li><li>2010年03月25日 -- <a href="http://www.ihiro.org/the-enhanced-ajax-effect-instructions" title="Ajax:近期博客改版的增强Ajax加载说明">Ajax:近期博客改版的增强Ajax加载说明</a> (43)</li><li>2009年09月6日 -- <a href="http://www.ihiro.org/highlight-the-administrators-reply-message" title="Wordpress:高亮管理员的留言信息">Wordpress:高亮管理员的留言信息</a> (37)</li><li>2010年08月12日 -- <a href="http://www.ihiro.org/sizzle-custom-selector" title="Sizzle:开源JS选择器，如何自定义选择器">Sizzle:开源JS选择器，如何自定义选择器</a> (31)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/the-effection-of-tab-like-msn" title="jQuery:仿MSN网站的tab效果">jQuery:仿MSN网站的tab效果</a> (30)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/use-git-synchronize-code-to-github/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>CSS3:Transition属性详解</title>
		<link>http://www.ihiro.org/css3-transition</link>
		<comments>http://www.ihiro.org/css3-transition#comments</comments>
		<pubDate>Wed, 20 Apr 2011 06:40:44 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[HTML5、CSS3]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[学习笔记]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1656</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/04/css3-transition.png" alt="" title="css3-transition" width="100" height="100" class="alignleft size-full wp-image-1659" />
<p class="red"><strong>因博客服务器瘫痪，上周的所有数据丢失。该文为恢复后补发。</strong></p>
<p>暂时不做HTML5读书笔记的更新，下一篇再继续。临时性地插入CSS3新属性的详细介绍，以便可以和HTML5的知识结合起来合理应用，这样达到两者配合。</p>
<p>Transition属性主要是用来对某个CSS属性的变化过程进行控制，官方的介绍是”<em>CSS Transitions allow property changes in CSS values to occur smoothly over a specified duration.</em>“。而我个人则简单地理解为”<span class="green">在某个时间段内，平滑地改变某个CSS属性。</span>“。</p>
<p>Transition又包含了四个子属性，分别为property、duration、timing-function、delay。下面来一一介绍，在最后会给出一个简单的实例和使用方法说明。</p>]]></description>
			<content:encoded><![CDATA[<p class="red"><strong>因博客服务器瘫痪，上周的所有数据丢失。该文为恢复后补发。</strong></p>
<p>暂时不做HTML5读书笔记的更新，下一篇再继续。临时性地插入CSS3新属性的详细介绍，以便可以和HTML5的知识结合起来合理应用，这样达到两者配合。</p>
<p>Transition属性主要是用来对某个CSS属性的变化过程进行控制，官方的介绍是”<em>CSS Transitions allow property changes in CSS values to occur smoothly over a specified duration.</em>“。而我个人则简单地理解为”<span class="green">在某个时间段内，平滑地改变某个CSS属性。</span>“。</p>
<p>Transition又包含了四个子属性，分别为property、duration、timing-function、delay。下面来一一介绍，在最后会给出一个简单的实例和使用方法说明。</p>
<h3>1. transition-property:</h3>
<p>property针对了当前选择器的某个css属性进行设置。比如我要过渡一个背景色时，则设置property值为background。</p>
<h3>2. transition-duration:</h3>
<p>duration针对了过渡效果的持续时间。</p>
<h3>3. transition-timing-function:</h3>
<p>timing-function算是Transition属性中最为复杂的一个了。它针对了过渡效果的特效，有多种特效展示。这里得涉及到一个学术性的话题：貝茲曲線。说实话，我也没搞的太明白，但W3C给出了一张曲线图，一看就明白了（后附图）。</p>
<div>介绍下预留的几个特效：<br />
ease: cubic-bezier(0.25, 0.1, 0.25, 1.0)<br />
linear: cubic-bezier(0.0, 0.0, 1.0, 1.0)<br />
ease-in: cubic-bezier(0.42, 0, 1.0, 1.0)<br />
ease-out: cubic-bezier(0, 0, 0.58, 1.0)<br />
ease-in-out: cubic-bezier(0.42, 0, 0.58, 1.0)<br />
cubic-bezier(x1, y1, x2, y2) 为自定义，x1,x2,y1,y2的值范围在[0, 1]<br />
其中的cubic-bezier即为貝茲曲線中的绘制方法。先来看图：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/04/css3-transition.jpg" alt="" title="css3-transition" width="366" height="347" class="aligncenter size-full wp-image-1657" />图上有四点，P0-3，其中P0、P3是默认的点，对应了[0,0], [1,1]。而剩下的P1、P2两点则是我们通过cubic-bezier()自定义的。</div>
<p><strong>参考阅读：</strong><br />
W3C: <a href="http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag" rel="external">http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag</a><br />
貝茲曲線：<a href="http://zh.wikipedia.org/wiki/%E8%B2%9D%E8%8C%B2%E6%9B%B2%E7%B7%9A" rel="external">http://zh.wikipedia.org/wiki/%E8%B2%9D%E8%8C%B2%E6%9B%B2%E7%B7%9A</a></p>
<h3>4. transition-delay:</h3>
<p>duration针对了过渡效果的延迟执行时间。</p>
<h3>5. 代码演示：</h3>
<dl class="outer_dl">
<dt>1). 过渡单个属性：</dt>
<dd>

<div class="wp_codebox"><table><tr id="p16563"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1656code3"><pre class="css" style="font-family:monospace;">transition-property<span style="color: #00AA00;">:</span>opacity<span style="color: #00AA00;">;</span>
transition-duration<span style="color: #00AA00;">:</span>2s<span style="color: #00AA00;">;</span>
transition-timing-function<span style="color: #3333ff;">:ease-</span>in<span style="color: #00AA00;">;</span>
transition-delay<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span></pre></td></tr></table></div>

</dd>
<dt>2). 过渡多个属性：</dt>
<dd>
<dl class="inner_dl">
<dt>[1]. 上下一一对应型：</dt>
<dd>

<div class="wp_codebox"><table><tr id="p16564"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1656code4"><pre class="css" style="font-family:monospace;">transition-property<span style="color: #3333ff;">:opacity </span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
transition-duration<span style="color: #00AA00;">:</span>2s<span style="color: #00AA00;">,</span> 4s<span style="color: #00AA00;">;</span>
transition-timing-function<span style="color: #3333ff;">:ease-</span>in<span style="color: #00AA00;">;</span>
transition-delay<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span></pre></td></tr></table></div>

<p>此时：opacity过渡时间为2s，left过渡时间为4s。</dd>
<dt>[2]. 循环对应型：</dt>
<dd>

<div class="wp_codebox"><table><tr id="p16565"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1656code5"><pre class="css" style="font-family:monospace;">transition-property<span style="color: #3333ff;">:opacity </span><span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">width</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">;</span>
transition-duration<span style="color: #00AA00;">:</span>2s<span style="color: #00AA00;">,</span> 4s<span style="color: #00AA00;">;</span>
transition-timing-function<span style="color: #3333ff;">:ease-</span>in<span style="color: #00AA00;">;</span>
transition-delay<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span></pre></td></tr></table></div>

<p>此时：opacity和width过渡时间为2s，left和height过渡时间为4s。</dd>
</dl>
</dd>
<dt>3). transition简写模式：</dt>
<dd>顺序为：transition-property transition-duration transition-timing-function transition-delay</p>

<div class="wp_codebox"><table><tr id="p16566"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1656code6"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*单个属性：*/</span>
-moz-transition<span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">background</span> 0.5s ease-out 0s<span style="color: #00AA00;">;</span>
<span style="color: #808080; font-style: italic;">/*多个属性：*/</span>
-moz-transition<span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">,</span> 0.5s ease-out 0s<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">color</span> <span style="color: #cc66cc;">0.4</span> ease-out 0s<span style="color: #00AA00;">;</span></pre></td></tr></table></div>

</dd>
</dl>
<h3>6. 实例展示：</h3>
<p>请用火狐打开，暂没添加其他浏览器支持。有兴趣的可以到Demo页面，下了源代码自行添加后测试。也可以查看我的头部导航，也用到了Transition的效果。</p>
<p class="demo-down-bar"><a href="http://ihiro.org/html5-css3/CSS3/01.transition.html" class="demo" rel="external">Demo</a></p>
<div>HTML代码：</p>

<div class="wp_codebox"><table><tr id="p16567"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1656code7"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;http://www.ihiro.org/&quot; target=&quot;_blank&quot;&gt;ihiro.org&lt;/a&gt;</pre></td></tr></table></div>

</div>
<div>CSS代码：</p>

<div class="wp_codebox"><table><tr id="p16568"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p1656code8"><pre class="css" style="font-family:monospace;">&lt;a href<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;http://www.ihiro.org/&quot;</span> target<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;_blank&quot;</span><span style="color: #00AA00;">&gt;</span>ihiro.org&lt;/a<span style="color: #00AA00;">&gt;</span>
a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">160px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#33589f</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-transform</span><span style="color: #00AA00;">:</span><span style="color: #993333;">uppercase</span><span style="color: #00AA00;">;</span>
    <span style="color: #808080; font-style: italic;">/*只有当鼠标移出后才处理*/</span>
    -moz-transition<span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">background</span> 0.2s linear 0s<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#263c7b</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f60</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span> <span style="color: #933;">2px</span> <span style="color: #933;">10px</span> <span style="color: #cc00cc;">#f00</span><span style="color: #00AA00;">;</span>
    <span style="color: #808080; font-style: italic;">/* 只有当鼠标移入时才处理
       注：若a:hover中不写transition,则会继承a中的transition */</span>
    <span style="color: #808080; font-style: italic;">/*
    1. 单个属性
        -moz-transition:background 0.5s ease-out 0s;
    2. 多个属性：
       -moz-transition:background, 0.5s ease-out 0s, color 0.4 ease-out 0s;
    */</span>
    -moz-transition<span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">background</span> 0.5s ease-out<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">color</span> 0.4s ease-out<span style="color: #00AA00;">,</span> <span style="color: #000000; font-weight: bold;">text-shadow</span> 0.3s linear<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</div>
<p>更多的Transition相关请阅读：<a href="http://www.w3.org/TR/css3-transitions/" rel="external">http://www.w3.org/TR/css3-transitions/</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li><li>2010年11月22日 -- <a href="http://www.ihiro.org/text-range" title="Range:文本框选区学习笔记">Range:文本框选区学习笔记</a> (16)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2010年12月30日 -- <a href="http://www.ihiro.org/javascript-getweek-by-date" title="Javascript:根据指定日期获得星期数">Javascript:根据指定日期获得星期数</a> (23)</li><li>2010年11月25日 -- <a href="http://www.ihiro.org/css-position-hack" title="CSS:position属性定位总结">CSS:position属性定位总结</a> (28)</li><li>2010年11月3日 -- <a href="http://www.ihiro.org/html5-pro-ebook-recommendations" title="HTML5:《Pro HTML5 Programming》英文电子书推荐">HTML5:《Pro HTML5 Programming》英文电子书推荐</a> (21)</li><li>2010年08月12日 -- <a href="http://www.ihiro.org/sizzle-custom-selector" title="Sizzle:开源JS选择器，如何自定义选择器">Sizzle:开源JS选择器，如何自定义选择器</a> (31)</li><li>2010年07月4日 -- <a href="http://www.ihiro.org/perforomance-best-pritices-for-web-developers" title="读书:《高性能网站建设进阶指南:Web开发者性能优化最佳实践 》">读书:《高性能网站建设进阶指南:Web开发者性能优化最佳实践 》</a> (10)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/css3-transition/feed</wfw:commentRss>
		<slash:comments>82</slash:comments>
		</item>
		<item>
		<title>HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</title>
		<link>http://www.ihiro.org/html5-reading-note-chp4-canvas</link>
		<comments>http://www.ihiro.org/html5-reading-note-chp4-canvas#comments</comments>
		<pubDate>Fri, 01 Apr 2011 06:11:03 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[HTML5、CSS3]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[学习笔记]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1648</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/04/canvas-logo.png" alt="" title="canvas-logo" width="100" height="100" class="alignleft size-full wp-image-1650" />
<p>《HTML5》的第四章节主要是对Canvas标签的属性以及相应的API进行了介绍，给出实例，这样学习起来就更加地容易和生动。</p>
<p>今天是愚人节，特意选择今天更新一篇博文。倒不是因为文章的内容和愚人节有什么关系，只是做个纪念。同时也是纪念一下哥哥（张国荣）去世8周年。</p>
<p>给出五个简单的实例，通过这些实例可以对Canvas的API有一个简要的认识和了解。在代码中也附加了注释，这样可以清楚地了解该行代码的含义。</p>]]></description>
			<content:encoded><![CDATA[<p>《HTML5》的第四章节主要是对Canvas标签的属性以及相应的API进行了介绍，给出实例，这样学习起来就更加地容易和生动。</p>
<p>今天是愚人节，特意选择今天更新一篇博文。倒不是因为文章的内容和愚人节有什么关系，只是做个纪念。同时也是纪念一下哥哥（张国荣）去世8周年。</p>
<p>给出五个简单的实例，通过这些实例可以对Canvas的API有一个简要的认识和了解。在代码中也附加了注释，这样可以清楚地了解该行代码的含义。</p>
<h3>一、绘制矩形：</h3>
<p>查看效果：<a href="http://ihiro.org/html5-css3/reading/CHP4.Canvas/1.drawRect.html" rel="external">1.drawRect.html</a></p>

<div class="wp_codebox"><table><tr id="p16489"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p1648code9"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> rect <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rect'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'2d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//画一个80x80的正方形</span>
rect.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'#eee'</span><span style="color: #339933;">;</span>
rect.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">90</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">90</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//在80x80的正方形中间截去一个50x50的正方形</span>
rect.<span style="color: #660066;">clearRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">70</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">70</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//画一个空心的80x80的正方形</span>
rect.<span style="color: #660066;">strokeStyle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'#ccc'</span><span style="color: #339933;">;</span>
rect.<span style="color: #660066;">strokeRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">100.5</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100.5</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">180</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">180</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    <span style="color: #006600; font-style: italic;">//.5 for line width(two side), 2x0.5=1px</span></pre></td></tr></table></div>

</p>
<h3>二、绘制线条：</h3>
<p>查看效果：<a href="http://ihiro.org/html5-css3/reading/CHP4.Canvas/2.drawLine.html" rel="external">2.drawLine.html</a></p>

<div class="wp_codebox"><table><tr id="p164810"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p1648code10"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> line <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'line'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'2d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//画一条垂直线</span>
line.<span style="color: #660066;">moveTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
line.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//画一条斜角线</span>
line.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">80</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//再一条斜角线闭合三角形</span>
line.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">20</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//给三角形边线着色</span>
line.<span style="color: #660066;">strokeStyle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'#f00'</span><span style="color: #339933;">;</span>
line.<span style="color: #660066;">stroke</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>三、绘制文本：</h3>
<p>查看效果：<a href="http://ihiro.org/html5-css3/reading/CHP4.Canvas/3.drawText.html" rel="external">3.drawText.html</a></p>

<div class="wp_codebox"><table><tr id="p164811"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code" id="p1648code11"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> context <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'text'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'2d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">beginPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">moveTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">240</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #006600; font-style: italic;">//预留20px的空白</span>
context.<span style="color: #660066;">moveTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">260</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//画右上的箭头</span>
context.<span style="color: #660066;">moveTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">495</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">35</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">40</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">495</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">45</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
context.<span style="color: #660066;">moveTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">60</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">60</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">153</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    <span style="color: #006600; font-style: italic;">//预留20px的空白</span>
context.<span style="color: #660066;">moveTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">60</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">173</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">60</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">375</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//画左下的箭头</span>
context.<span style="color: #660066;">moveTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">65</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">370</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">60</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">375</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">lineTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">55</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">370</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//着色</span>
context.<span style="color: #660066;">strokeStyle</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;#000&quot;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">stroke</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
context.<span style="color: #660066;">font</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;bold 12px sans-serif&quot;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//标注X坐标文字</span>
context.<span style="color: #660066;">fillText</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;x&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">248</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">43</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//标注Y坐标文字</span>
context.<span style="color: #660066;">fillText</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;y&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">58</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">165</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
context.<span style="color: #660066;">textBaseline</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;top&quot;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//标注起始坐标文字</span>
context.<span style="color: #660066;">fillText</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;(0, 0)&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//画左上角的标识点</span>
context.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
context.<span style="color: #660066;">textAlign</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;right&quot;</span><span style="color: #339933;">;</span>
context.<span style="color: #660066;">textBaseline</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;bottom&quot;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//标注结束坐标文字</span>
context.<span style="color: #660066;">fillText</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;(500, 375)&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">492</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">370</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//画右下角的标识点</span>
context.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">494</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">372</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>四、绘制渐变：</h3>
<p>查看效果：<a href="http://ihiro.org/html5-css3/reading/CHP4.Canvas/4.drawGradients.html" rel="external">4.drawGradients.html</a></p>

<div class="wp_codebox"><table><tr id="p164812"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p1648code12"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> context <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'gradients'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'2d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//创建一个宽300px的线性渐变， 决定了渐变方向，仅x1为横向， 仅x2为纵向， 两者都有为对角线渐变</span>
<span style="color: #003366; font-weight: bold;">var</span> my_gradients <span style="color: #339933;">=</span> context.<span style="color: #660066;">createLinearGradient</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">300</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">225</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//起始色：黑色</span>
my_gradients.<span style="color: #660066;">addColorStop</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'black'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//终止色： 白色</span>
my_gradients.<span style="color: #660066;">addColorStop</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'white'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//设置填充色</span>
context.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> my_gradients<span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//画300x225尺寸的线性渐变矩形</span>
context.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">300</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">225</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>五、绘制图片：</h3>
<p>查看效果：<a href="http://ihiro.org/html5-css3/reading/CHP4.Canvas/5.drawImage.html" rel="external">5.drawImage.html</a></p>

<div class="wp_codebox"><table><tr id="p164813"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p1648code13"><pre class="javascript" style="font-family:monospace;">window.<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>
    <span style="color: #003366; font-weight: bold;">var</span> context <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'image'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'2d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> cat <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'cat'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//坐标5, 5处绘入 - 源图</span>
    context.<span style="color: #660066;">drawImage</span><span style="color: #009900;">&#40;</span>cat<span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//坐标100, 100处绘入 - 源图缩放成80x60尺寸</span>
    context.<span style="color: #660066;">drawImage</span><span style="color: #009900;">&#40;</span>cat<span style="color: #339933;">,</span> <span style="color: #CC0000;">120</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">120</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">80</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">//坐标200, 200处绘入 - 源图从10,10处取160x100尺寸，缩放到80x50尺寸</span>
    context.<span style="color: #660066;">drawImage</span><span style="color: #009900;">&#40;</span>cat<span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">160</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">80</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</p>
<p>下载本篇文章的代码压缩包：<a href="http://ihiro.org/html5-css3/reading/CHP4.Canvas/CHP4.Canvas.zip" rel="external">CHP4.Canvas.zip</a></p>
<h3>附加信息：</h3>
<p><strong class="green">开源代码，兼容主流浏览器，IE下都是通过VML实现兼容：</strong><br />
Google Code Canvas库：<a href="http://code.google.com/p/explorercanvas/" rel="external">http://code.google.com/p/explorercanvas/</a><br />
jQuery Maphilight 插件：<a href="http://davidlynch.org/js/maphilight/docs/" rel="external">http://davidlynch.org/js/maphilight/docs/</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li><li>2010年11月22日 -- <a href="http://www.ihiro.org/text-range" title="Range:文本框选区学习笔记">Range:文本框选区学习笔记</a> (16)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2010年12月30日 -- <a href="http://www.ihiro.org/javascript-getweek-by-date" title="Javascript:根据指定日期获得星期数">Javascript:根据指定日期获得星期数</a> (23)</li><li>2010年11月3日 -- <a href="http://www.ihiro.org/html5-pro-ebook-recommendations" title="HTML5:《Pro HTML5 Programming》英文电子书推荐">HTML5:《Pro HTML5 Programming》英文电子书推荐</a> (21)</li><li>2009年12月18日 -- <a href="http://www.ihiro.org/10-javascript-tips" title="Javascript:10个Javscript编程的技巧">Javascript:10个Javscript编程的技巧</a> (4)</li><li>2009年09月10日 -- <a href="http://www.ihiro.org/javascript-oop" title="Javascript:面向对象之静态、公有、私有、特权对象">Javascript:面向对象之静态、公有、私有、特权对象</a> (10)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2011年02月24日 -- <a href="http://www.ihiro.org/scroll-images" title="Javascript:图片无限循环滚动">Javascript:图片无限循环滚动</a> (27)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/html5-reading-note-chp4-canvas/feed</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</title>
		<link>http://www.ihiro.org/html5-reading-note-chp3-elements</link>
		<comments>http://www.ihiro.org/html5-reading-note-chp3-elements#comments</comments>
		<pubDate>Mon, 21 Mar 2011 06:17:59 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[HTML5、CSS3]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[学习笔记]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1634</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/03/html5-elements.gif" alt="" title="html5-elements" width="100" height="100" class="alignleft size-full wp-image-1637" />
<p>即上篇的<a href="http://www.ihiro.org/html5-reading-note-chp2-features" rel="external">特性章节</a>之后，继续更新我的HTML5读书笔记。本篇主要记录一些标签方面的更新注意事项。一些普通的header、nav、article等标签的用法网上是一大堆，我只是把我觉得这方面重要的内容或者不容易记住的内容做了一个备份。</p>
<p>这些新的HTML5标签在IE8及以下版本中都不能支持，这就需要在页面加载之前使用JS动态地创建HTML5新标签，以实现页面的正确的渲染。当然这样处理并不是万能的，在处理一些AJAX交互时，就会出现返回的HTML5标签无法正确解析的问题。此时就需要<a href="http://jdbartlett.github.com/innershiv/" rel="internal">HTML5 innerShiv</a>来解决了。</p>]]></description>
			<content:encoded><![CDATA[<p>即上篇的<a href="http://www.ihiro.org/html5-reading-note-chp2-features" rel="external">特性章节</a>之后，继续更新我的HTML5读书笔记。本篇主要记录一些标签方面的更新注意事项。一些普通的header、nav、article等标签的用法网上是一大堆，我只是把我觉得这方面重要的内容或者不容易记住的内容做了一个备份。</p>
<p>这些新的HTML5标签在IE8及以下版本中都不能支持，这就需要在页面加载之前使用JS动态地创建HTML5新标签，以实现页面的正确的渲染。当然这样处理并不是万能的，在处理一些AJAX交互时，就会出现返回的HTML5标签无法正确解析的问题。此时就需要<a href="http://jdbartlett.github.com/innershiv/" rel="internal">HTML5 innerShiv</a>来解决了。</p>
<h3>1. Doctype:</h3>
<p>
<div class="wp_codebox"><table><tr id="p163414"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1634code14"><pre class="html" style="font-family:monospace;">&lt; !DOCTYPE html&gt;</pre></td></tr></table></div>

<p>无需再去添加XHTML的框架型、过渡性或者严谨型的声明。</p>
<h3>2. HTML</h3>
<p>
<div class="wp_codebox"><table><tr id="p163415"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1634code15"><pre class="html" style="font-family:monospace;">&lt;html lang=&quot;en&quot;&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>无需再添加xmlns属性来约束标签的命名空间了。</p>
<h3>3. HEAD:</h3>
<dl class="outer_dl">
<dt>1).meta:</dt>
<dd>

<div class="wp_codebox"><table><tr id="p163416"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1634code16"><pre class="html" style="font-family:monospace;">&lt;meta charset=&quot;utf-8&quot; /&gt;</pre></td></tr></table></div>

</dd>
<dt>2).link:</dt>
<dd>
<dl class="inner_dl">
<dt>2.1).rel=”stylesheet”</dt>
<dd>

<div class="wp_codebox"><table><tr id="p163417"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1634code17"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; href=&quot;style-original.css&quot; /&gt;</pre></td></tr></table></div>

</dd>
<dt>2.2).rel=”alertnate”     //用在订阅</dt>
<dd>

<div class="wp_codebox"><table><tr id="p163418"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1634code18"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;alternate&quot; type=&quot;application/atom+xml&quot; title=&quot;My Weblog feed&quot; href=&quot;/feed/&quot; /&gt;</pre></td></tr></table></div>

</dd>
<dt>2.3).rel=”icon”</dt>
<dd>

<div class="wp_codebox"><table><tr id="p163419"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1634code19"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;shortcut icon&quot; href=&quot;/favicon.ico&quot;&gt;&lt;/link&gt;</pre></td></tr></table></div>

</dd>
</dl>
</dd>
</dl>
<h3>4. How to style unknown elements in IE:</h3>
<p>
<div class="wp_codebox"><table><tr id="p163420"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p1634code20"><pre class="html" style="font-family:monospace;">     &lt;!--[if lt IE 9]&gt;
          &lt;script type=&quot;text/javascript&quot;&gt;
               var e = (&quot;abbr,article,aside,audio,canvas,datalist,details,&quot; +
                         &quot;figure,footer,header,hgroup,mark,menu,meter,nav,output,&quot; +
                         &quot;progress,section,time,video&quot;).split(',');
               for (var i = 0; i &lt; e.length; i++) {
                    document.createElement(e[i]);
               }
          &lt;/script&gt;
     &lt; ![endif]--&gt;&lt;/script&gt;</pre></td></tr></table></div>

<p>OR:</p>

<div class="wp_codebox"><table><tr id="p163421"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1634code21"><pre class="html" style="font-family:monospace;">     &lt;!--[if lt IE 9]&gt;
          &lt;script type=&quot;text/javascript&quot; src=&quot;http://html5shiv.googlecode.com/svn/trunk/html5.js&quot;&gt;&lt;/script&gt;
     &lt; ![endif]--&gt;</pre></td></tr></table></div>

</p>
<h3>5. The HTML5 algorithm says that an &lt;article&gt; element creates a new section, that is, a new node in the document outline. And in HTML5, each section can have its own &lt;h1&gt; element.</h3>
<h3>6. Time and Date:</h3>
<p>
<div class="wp_codebox"><table><tr id="p163422"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1634code22"><pre class="html" style="font-family:monospace;">&lt;time datetime=&quot;2009-10-22&quot; pubdate=&quot;pubdate&quot;&gt;October 22, 2009&lt;/time&gt;</pre></td></tr></table></div>
</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li><li>2010年11月22日 -- <a href="http://www.ihiro.org/text-range" title="Range:文本框选区学习笔记">Range:文本框选区学习笔记</a> (16)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2010年12月30日 -- <a href="http://www.ihiro.org/javascript-getweek-by-date" title="Javascript:根据指定日期获得星期数">Javascript:根据指定日期获得星期数</a> (23)</li><li>2010年11月3日 -- <a href="http://www.ihiro.org/html5-pro-ebook-recommendations" title="HTML5:《Pro HTML5 Programming》英文电子书推荐">HTML5:《Pro HTML5 Programming》英文电子书推荐</a> (21)</li><li>2009年12月18日 -- <a href="http://www.ihiro.org/10-javascript-tips" title="Javascript:10个Javscript编程的技巧">Javascript:10个Javscript编程的技巧</a> (4)</li><li>2009年09月10日 -- <a href="http://www.ihiro.org/javascript-oop" title="Javascript:面向对象之静态、公有、私有、特权对象">Javascript:面向对象之静态、公有、私有、特权对象</a> (10)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2011年02月24日 -- <a href="http://www.ihiro.org/scroll-images" title="Javascript:图片无限循环滚动">Javascript:图片无限循环滚动</a> (27)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/html5-reading-note-chp3-elements/feed</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</title>
		<link>http://www.ihiro.org/html5-reading-note-chp2-features</link>
		<comments>http://www.ihiro.org/html5-reading-note-chp2-features#comments</comments>
		<pubDate>Tue, 15 Mar 2011 02:55:31 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[HTML5、CSS3]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[学习笔记]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1626</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/03/html5_logo.gif" alt="" title="html5_logo" width="100" height="100" class="alignleft size-full wp-image-1627" />
<p>HTML5最近确实很火，逼的我不得不继续自学下去。去年年底的时候看了一些《Pro HTML5》的章节。因为过年，后来就断掉了。除了一些练习的代码外，没留下什么笔记。</p>
<p>年后没多久我就开始看起了《HTML5. Up and Running》这本书，中文版《HTML5揭秘》已经上市。我到今天也看到了第六章。摘取了一些扼要的东西，做了一些简单的笔记，以便以后的翻查。Everbox这个时候就发挥到了作用，让我随时随地想翻的时候都可以翻一翻。</p>
<p class="green">这篇文章只是开篇，后面会陆续有些我自己的笔记分享，很简单的文字。</p>]]></description>
			<content:encoded><![CDATA[<p>HTML5最近确实很火，逼的我不得不继续自学下去。去年年底的时候看了一些《Pro HTML5》的章节。因为过年，后来就断掉了。除了一些练习的代码外，没留下什么笔记。</p>
<p>年后没多久我就开始看起了《HTML5. Up and Running》这本书，中文版《HTML5揭秘》已经上市。我到今天也看到了第六章。摘取了一些扼要的东西，做了一些简单的笔记，以便以后的翻查。Everbox这个时候就发挥到了作用，让我随时随地想翻的时候都可以翻一翻。</p>
<p class="green">这篇文章只是开篇，后面会陆续有些我自己的笔记分享，很简单的文字。</p>
<p>本文介绍的是HTML5特性判断：</p>
<h3>1. Canvas:</h3>
<p>
<div class="wp_codebox"><table><tr id="p162623"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1626code23"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">!!</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'canvas'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getContext</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>2. Video:</h3>
<p>
<div class="wp_codebox"><table><tr id="p162624"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1626code24"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">!!</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'video'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">canPlayType</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Video Formats:</p>

<div class="wp_codebox"><table><tr id="p162625"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1626code25"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> v <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;video&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">return</span> v.<span style="color: #660066;">canPlayType</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'video/mp4; codecs=&quot;avc1.42E01E, mp4a.40.2&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>3. Local Storage: </h3>
<p>
<div class="wp_codebox"><table><tr id="p162626"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1626code26"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'localStorage'</span> <span style="color: #000066; font-weight: bold;">in</span> window<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> window<span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'localStorage'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>4. Web Workers:</h3>
<p>
<div class="wp_codebox"><table><tr id="p162627"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1626code27"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">!!</span>window.<span style="color: #660066;">Worker</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>5. Offline Web Applications:</h3>
<p>
<div class="wp_codebox"><table><tr id="p162628"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1626code28"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">!!</span>window.<span style="color: #660066;">applicationCache</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>6. Geolocation:</h3>
<p>
<div class="wp_codebox"><table><tr id="p162629"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1626code29"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">!!</span>navigator.<span style="color: #660066;">geolocation</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>7. From:</h3>
<p>
Input:</p>

<div class="wp_codebox"><table><tr id="p162630"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1626code30"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
i.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;type&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;color&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">return</span> i.<span style="color: #660066;">type</span> <span style="color: #339933;">!==</span> <span style="color: #3366CC;">&quot;text&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Placeholder Text:</p>

<div class="wp_codebox"><table><tr id="p162631"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1626code31"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'placeholder'</span> <span style="color: #000066; font-weight: bold;">in</span> i<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Form Autofocus:</p>

<div class="wp_codebox"><table><tr id="p162632"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1626code32"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'autofocus'</span> <span style="color: #000066; font-weight: bold;">in</span> i<span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>8. Microdata:</h3>
<p>
<div class="wp_codebox"><table><tr id="p162633"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1626code33"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #339933;">!!</span>document.<span style="color: #660066;">getItems</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2010年11月22日 -- <a href="http://www.ihiro.org/text-range" title="Range:文本框选区学习笔记">Range:文本框选区学习笔记</a> (16)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2010年12月30日 -- <a href="http://www.ihiro.org/javascript-getweek-by-date" title="Javascript:根据指定日期获得星期数">Javascript:根据指定日期获得星期数</a> (23)</li><li>2010年11月3日 -- <a href="http://www.ihiro.org/html5-pro-ebook-recommendations" title="HTML5:《Pro HTML5 Programming》英文电子书推荐">HTML5:《Pro HTML5 Programming》英文电子书推荐</a> (21)</li><li>2009年12月18日 -- <a href="http://www.ihiro.org/10-javascript-tips" title="Javascript:10个Javscript编程的技巧">Javascript:10个Javscript编程的技巧</a> (4)</li><li>2009年09月10日 -- <a href="http://www.ihiro.org/javascript-oop" title="Javascript:面向对象之静态、公有、私有、特权对象">Javascript:面向对象之静态、公有、私有、特权对象</a> (10)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2011年02月24日 -- <a href="http://www.ihiro.org/scroll-images" title="Javascript:图片无限循环滚动">Javascript:图片无限循环滚动</a> (27)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/html5-reading-note-chp2-features/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>CSS:区分IE版本的三个方法</title>
		<link>http://www.ihiro.org/css-specific-for-internet-explorer</link>
		<comments>http://www.ihiro.org/css-specific-for-internet-explorer#comments</comments>
		<pubDate>Wed, 02 Mar 2011 02:59:37 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[CSS、XHTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[技巧]]></category>
		<category><![CDATA[译文]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1612</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/03/ie-specific-css.png" alt="" title="ie-specific-css" width="100" height="100" class="alignleft size-full wp-image-1616" />
<p>虽然我们从心理上都不愿意去处理IE的bug，但我们不得不面对老板和浏览者们仍然在使用IE。介于不同浏览器有不同的渲染器，这往往会使开发者们感到很沮丧。我们通常使用IE条件判断语言来处理IE的CSS问题，但其实还是有其他的一些方法来处理IE的CSS bug的。</p>
<p>一、IE条件判断语句； 二、CSS规则（IE CSS hacks）； 三、HTML条件判断，给出不同的className。</p>
<p>本文翻译自：<a href="http://www.webdesignerwall.com/tutorials/css-specific-for-internet-explorer/" rel="external">CSS Specific for Internet Explorer</a></p>]]></description>
			<content:encoded><![CDATA[<p>虽然我们从心理上都不愿意去处理IE的bug，但我们不得不面对老板和浏览者们仍然在使用IE。介于不同浏览器有不同的渲染器，这往往会使开发者们感到很沮丧。我们通常使用IE条件判断语言来处理IE的CSS问题，但其实还是有其他的一些方法来处理IE的CSS bug的。</p>
<h3>一、IE条件判断语句</h3>
<p>IE条件判断语句也许是用的最多的区分IE版本(IE6, IE7, IE8)的办法了。看看下面用来区分IE不同版本的代码：</p>
<ul>
<li>* <code>&lt;!--[if IE 8]&gt;</code> = IE8版本</li>
<li>* <code>&lt;!--[if lt IE 8]&gt;</code> = IE7版本以低版本</li>
<li>* <code>&lt;!--[if gte IE 8]&gt;</code> = IE8版本及高版本</li>
</ul>
<p>
<div class="wp_codebox"><table><tr id="p161234"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p1612code34"><pre class="html" style="font-family:monospace;">&lt;!--[if IE 8]&gt;
&lt;style type=&quot;text/css&quot;&gt;
	/* css for IE 8 */
&lt;/style&gt;
&lt; ![endif]--&gt;
&nbsp;
&lt;!--[if lt IE 8]&gt;
	&lt;link href=&quot;ie7.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt; ![endif]--&gt;</pre></td></tr></table></div>

</p>
<h3>二、CSS规则（IE CSS hacks）</h3>
<p>另一个办法就是在样式文件中声明只有IE识别的CSS规则。比如，在CSS属性前置一个”*”区分IE7和低版本，而前置一个”_”则区分IE6及低版本。但是，很多时候这个方法不被推荐，因为这些CSS规则并不能被W3C CSS 验证成功。</p>
<ul>
<li>* IE8 及 低版本: 在CSS属性后置”\9&#8243;, 如 <code>height:1000px\9;</code></li>
<li>* IE7 及 低版本: 在CSS属性前置”*”, 如 <code>*height:1000px;</code></li>
<li>* IE6 及 低版本: 在CSS属性前置”_”, 如 <code>_height:1000px;</code></li>
</ul>
<p>
<div class="wp_codebox"><table><tr id="p161235"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p1612code35"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.box</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">gray</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* standard */</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> pink\<span style="color: #cc66cc;">9</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* IE 8 and below */</span>
&nbsp;
	<span style="color: #00AA00;">*</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">green</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* IE 7 and below */</span>
&nbsp;
	_background<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">blue</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* IE 6 */</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</p>
<h3>三、HTML条件判断，给出不同的className</h3>
<p>第三个办法是由<a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/" rel="external">Paul Irish</a>发起的。它实现的办法是通过IE条件判断来给HTML设置不同的className，然后在CSS中通过给不同的className下的后代设置不同的样式即可实现。这个办法比较可行，也不会有任何W3C验证的问题。</p>
<p>
<div class="wp_codebox"><table><tr id="p161236"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p1612code36"><pre class="html" style="font-family:monospace;">&lt;!--[if lt IE 7 ]&gt; &lt;html class=&quot;ie6&quot;&gt; &lt; ![endif]--&gt;
&lt;!--[if IE 7 ]&gt; &lt;/html&gt;&lt;html class=&quot;ie7&quot;&gt; &lt; ![endif]--&gt;
&lt;!--[if IE 8 ]&gt; &lt;/html&gt;&lt;html class=&quot;ie8&quot;&gt; &lt; ![endif]--&gt;
&lt;!--[if IE 9 ]&gt; &lt;/html&gt;&lt;html class=&quot;ie9&quot;&gt; &lt; ![endif]--&gt;
&lt;!--[if (gt IE 9)|!(IE)]&gt;&lt;!--&gt; &lt;/html&gt;&lt;html&gt; &lt;!--&lt;![endif]--&gt;
&lt;/html&gt;</pre></td></tr></table></div>

</p>
<p>本文翻译自：<a href="http://www.webdesignerwall.com/tutorials/css-specific-for-internet-explorer/" rel="external">CSS Specific for Internet Explorer</a></p>
<p class="green">PS:这三种办法我个人都用过，只是第三中办法我不是给HTML便签设置不同的className,而是在BODY中所有HTML代码的最外层多嵌套了一层DIV。呵呵，想想，还是给HTML或BODY标签设置不同className比较合算。至少不会有多余的标签。</p>
<h3>扩展阅读：</h3>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx" rel="external">About Conditional Comments</a></li>
</ul>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年05月17日 -- <a href="http://www.ihiro.org/target-every-version-of-ie-from-a-single-stylesheet" title="CSS:通过一个样式表区分IE的各个版本">CSS:通过一个样式表区分IE的各个版本</a> (11)</li><li>2010年03月8日 -- <a href="http://www.ihiro.org/css3-basic" title="CSS:CSS3基础（附图）">CSS:CSS3基础（附图）</a> (12)</li><li>2009年09月3日 -- <a href="http://www.ihiro.org/share-some-common-techniques-of-css" title="CSS:分享一些常用的css技巧">CSS:分享一些常用的css技巧</a> (8)</li><li>2010年11月25日 -- <a href="http://www.ihiro.org/css-position-hack" title="CSS:position属性定位总结">CSS:position属性定位总结</a> (28)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年06月12日 -- <a href="http://www.ihiro.org/firefox-4-will-support-css3-calc-method" title="CSS:Firefox 4 将支持CSS3 calc方法">CSS:Firefox 4 将支持CSS3 calc方法</a> (18)</li><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年02月20日 -- <a href="http://www.ihiro.org/how-to-insert-googlebuzz-data-into-blog" title="Wordpress:如何将GoogleBuzz数据插入到博客中">Wordpress:如何将GoogleBuzz数据插入到博客中</a> (11)</li><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li><li>2010年01月20日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a> (6)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/css-specific-for-internet-explorer/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Javascript:图片无限循环滚动</title>
		<link>http://www.ihiro.org/scroll-images</link>
		<comments>http://www.ihiro.org/scroll-images#comments</comments>
		<pubDate>Thu, 24 Feb 2011 09:21:11 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[Pure Javascript]]></category>
		<category><![CDATA[Cases]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1604</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/02/scroll_logo.jpg" alt="" title="scroll_logo" width="100" height="100" class="alignleft size-full wp-image-1607" />
<p>早前为一位博友写了一个走马灯效果（<a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" rel="external">增强型走马灯公告栏，可以抛弃marquee标签了</a>，<a href="http://www.ihiro.org/cases/noticeBox/" rel="external">点击</a>看效果），但时是基于jQuery库写的。效果实现的优点牵强。而且当时的效果是页面加载完后一片空白，只有开始播放后才从底部出来。</p>
<p>年前用wordpress给公司做内部信息分享平台时，有一块是用来横向无限循环播放展示team building的图片。之前的效果不适合，便又写了一段原生的js来实现。主要实现原理是间隔时间地设置一个overflow:hidden;的div的scrollLeft。</p>]]></description>
			<content:encoded><![CDATA[<p>早前为一位博友写了一个走马灯效果（<a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" rel="external">增强型走马灯公告栏，可以抛弃marquee标签了</a>，<a href="http://www.ihiro.org/cases/noticeBox/" rel="external">点击</a>看效果），但时是基于jQuery库写的。效果实现的优点牵强。而且当时的效果是页面加载完后一片空白，只有开始播放后才从底部出来。</p>
<p>年前用wordpress给公司做内部信息分享平台时，有一块是用来横向无限循环播放展示team building的图片。之前的效果不适合，便又写了一段原生的js来实现。主要实现原理是间隔时间地设置一个overflow:hidden;的div的scrollLeft。</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/scrollImg/scrollImg.zip" class="download">download</a><a href="http://www.ihiro.org/cases/scrollImg/" rel="external" class="demo">demo</a></p>
<h3>一、HTML代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p160437"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p1604code37"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;photo-list&quot;&gt;
    &lt;ul id=&quot;scroll&quot;&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/intellij-idea&quot;&gt;&lt;img src=&quot;http://www.ihiro.org/blog/wp-content/uploads/2011/01/logo.jpg&quot; width=&quot;100px&quot; height=&quot;100px&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/javascript-getweek-by-date&quot;&gt;&lt;img src=&quot;http://www.ihiro.org/blog/wp-content/uploads/2010/12/calendar.jpg&quot; width=&quot;100px&quot; height=&quot;100px&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/beginning-python&quot;&gt;&lt;img src=&quot;http://www.ihiro.org/blog/wp-content/uploads/2010/12/beginning-python.jpg&quot; width=&quot;100px&quot; height=&quot;100px&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/css-position-hack&quot;&gt;&lt;img src=&quot;http://www.ihiro.org/blog/wp-content/uploads/2010/11/position-logo.jpg&quot; width=&quot;100px&quot; height=&quot;100px&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/text-range&quot;&gt;&lt;img src=&quot;http://www.ihiro.org/blog/wp-content/uploads/2010/11/text-range.jpg&quot; width=&quot;100px&quot; height=&quot;100px&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/html5-pro-ebook-recommendations&quot;&gt;&lt;img src=&quot;http://www.ihiro.org/blog/wp-content/uploads/2010/11/Pro_Html5_logo.jpg&quot; width=&quot;100px&quot; height=&quot;100px&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/jquery-plugin-recommended-maphighlight&quot;&gt;&lt;img src=&quot;http://www.ihiro.org/blog/wp-content/uploads/2010/10/maohightlight-logo.jpg&quot; width=&quot;100px&quot; height=&quot;100px&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/jquery-format-extend&quot;&gt;&lt;img src=&quot;http://www.ihiro.org/blog/wp-content/uploads/2010/09/jQuery.format_logo.png&quot; width=&quot;100px&quot; height=&quot;100px&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/information-september-2010-programming-language-list&quot;&gt;&lt;img src=&quot;http://www.ihiro.org/blog/wp-content/uploads/2010/08/2010.08.language-logo.jpg&quot; width=&quot;100px&quot; height=&quot;100px&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/example-selectbox-simulation&quot;&gt;&lt;img src=&quot;http://www.ihiro.org/blog/wp-content/uploads/2010/09/select_logo.png&quot; width=&quot;100px&quot; height=&quot;100px&quot; alt=&quot;&quot;/&gt;&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>使用一个无需列表，通过左浮横向显示。设置容器div的尺寸，超出部分不显示。
</p>
<h3>二、CSS代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p160438"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p1604code38"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#photo-list</span> <span style="color: #00AA00;">&#123;</span>
     <span style="color: #808080; font-style: italic;">/* 3张图片的宽度（包含宽度、padding、border、图片间的留白）
         计算：3*(100+2*2+1*2+9) - 9
         之所以减去9是第三张图片的右边留白
     */</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">336px</span><span style="color: #00AA00;">;</span>
    <span style="color: #808080; font-style: italic;">/* 图片的宽度（包含高度、padding、border）
        计算：100+2*2+1*2
    */</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">106px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">dashed</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#photo-list</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#photo-list</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#photo-list</span> img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>注释中写明了容器div的尺寸计算方法。页面加载完成后未播放时的效果：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/02/scroll_screenshot.jpg" alt="" title="scroll_screenshot" width="381" height="157" class="aligncenter size-full wp-image-1605" />
</p>
<p>Firebug查看尺寸图：<img src="http://www.ihiro.org/blog/wp-content/uploads/2011/02/scroll_size.jpg" alt="" title="scroll_size" width="378" height="169" class="aligncenter size-full wp-image-1606" /></p>
<h3>三、JS代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p160439"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code" id="p1604code39"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> id <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>el<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    c <span style="color: #339933;">=</span> id<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'photo-list'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>c<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span>	ul <span style="color: #339933;">=</span> id<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'scroll'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        lis <span style="color: #339933;">=</span> ul.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        itemCount <span style="color: #339933;">=</span> lis.<span style="color: #660066;">length</span><span style="color: #339933;">,</span>
        width <span style="color: #339933;">=</span> lis<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">offsetWidth</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">//获得每个img容器的宽度</span>
        marquee <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>
            c.<span style="color: #660066;">scrollLeft</span> <span style="color: #339933;">+=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>c.<span style="color: #660066;">scrollLeft</span> <span style="color: #339933;">%</span> width <span style="color: #339933;">&lt;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>  <span style="color: #006600; font-style: italic;">//当 c.scrollLeft 和 width 相等时，把第一个img追加到最后面</span>
                ul.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>ul.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                c.<span style="color: #660066;">scrollLeft</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</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>
        speed <span style="color: #339933;">=</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//数值越大越慢</span>
&nbsp;
    ul.<span style="color: #660066;">style</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> width<span style="color: #339933;">*</span>itemCount <span style="color: #339933;">+</span> <span style="color: #3366CC;">'px'</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//加载完后设置容器长度</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> timer <span style="color: #339933;">=</span> setInterval<span style="color: #009900;">&#40;</span>marquee<span style="color: #339933;">,</span> speed<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    c.<span style="color: #660066;">onmouseover</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>
        clearInterval<span style="color: #009900;">&#40;</span>timer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    c.<span style="color: #660066;">onmouseout</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>
        timer <span style="color: #339933;">=</span> setInterval<span style="color: #009900;">&#40;</span>marquee<span style="color: #339933;">,</span> speed<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></pre></td></tr></table></div>

<p>没有进行封装，只是实现效果。
</pre></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li><li>2010年12月30日 -- <a href="http://www.ihiro.org/javascript-getweek-by-date" title="Javascript:根据指定日期获得星期数">Javascript:根据指定日期获得星期数</a> (23)</li><li>2010年11月22日 -- <a href="http://www.ihiro.org/text-range" title="Range:文本框选区学习笔记">Range:文本框选区学习笔记</a> (16)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年02月24日 -- <a href="http://www.ihiro.org/javascript-news-flash-header-tips" title="Javascript:新消息闪烁标题提示代码分享">Javascript:新消息闪烁标题提示代码分享</a> (7)</li><li>2010年02月20日 -- <a href="http://www.ihiro.org/how-to-insert-googlebuzz-data-into-blog" title="Wordpress:如何将GoogleBuzz数据插入到博客中">Wordpress:如何将GoogleBuzz数据插入到博客中</a> (11)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/scroll-images/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Javascript:根据指定日期获得星期数</title>
		<link>http://www.ihiro.org/javascript-getweek-by-date</link>
		<comments>http://www.ihiro.org/javascript-getweek-by-date#comments</comments>
		<pubDate>Thu, 30 Dec 2010 08:06:25 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[Pure Javascript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1583</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/12/calendar.jpg" alt="" title="calendar" width="100" height="100" class="alignleft size-full wp-image-1584" />
<p>今天在写一个简单的日历程序，写着写着发现没办法把日期和头部的星期数对应起来，便通过Google搜索到了这个叫做“蔡勒（Zeller）公式”。根据这个公式写了个方法，发现还是蛮管用的。</p>
<p>不过就这个格式描述（见内页）来说少讲了一点，就是计算出来的结果若为负数的话，就需要再加上7，这样得出来的结果才是正确的。</p>
<p>当然这个公式不仅仅适合与JS,其他语言也可以写出来。原理一致...</p>]]></description>
			<content:encoded><![CDATA[<p>今天在写一个简单的日历程序，写着写着发现没办法把日期和头部的星期数对应起来，便通过Google搜索到了这个叫做“蔡勒（Zeller）公式”。根据这个公式写了个方法，发现还是蛮管用的。</p>
<blockquote class="quote"><p><span></p>
<p><strong>蔡勒（Zeller）公式：w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1</strong></p>
<p>公式中的符号含义如下，w：星期；c：世纪-1；y：年（两位数）；m：月（m 大于等于3，小于等于14，即在蔡勒公式中，某年的1、2月要看作上一年的13、14月来计算，比如2003年1月1日要看作2002年的13月1日来计算）；d：日；[ ]代表取整，即只要整数部分。(C是世纪数减一，y是年份后两位，M是月份，d是日数。1月和2月要按上一年的13月和 14月来算，这时C和y均按上一年取值。)</p>
<p>算出来的W除以7，余数是几就是星期几。如果余数是0，则为星期日。</p>
<p>以2049年10月1日（100周年国庆）为例，用蔡勒（Zeller）公式进行计算，过程如下：<br />蔡勒（Zeller）公式：w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1<br />=49+[49/4]+[20/4]-2×20+[26× (10+1)/10]+1-1<br />=49+[12.25]+5-40+[28.6]<br />=49+12+5-40+28<br />=54 (除以7余5)<br />即2049年10月1日（100周年国庆）是星期5。</p>
<p>摘自：<a href="http://www.cnblogs.com/chingho/archive/2010/03/26/1697282.html">http://www.cnblogs.com/chingho/archive/2010/03/26/1697282.html</a></p>
<p></span></p></blockquote>
<p>不过就这个格式描述来说少讲了一点，就是计算出来的结果若为负数的话，就需要再加上7，这样得出来的结果才是正确的。</p>
<p>当然这个公式不仅仅适合与JS,其他语言也可以写出来。原理一致&#8230;</p>
<p class="demo-down-bar"><a target="_blank" href="http://www.ihiro.org/cases/getWeek/getWeek.zip" rel="external" class="download">download</a> <a target="_blank" href="http://www.ihiro.org/cases/getWeek/" rel="external" class="demo">demo</a></p>
<h3>公式计算代码：</h3>

<div class="wp_codebox"><table><tr id="p158340"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code" id="p1583code40"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
 * 	获得指定日期的星期数，1-6为星期一到星期六，0为星期天
 *	@y 年份
 *	@m 月份
 *	@d 日
 */</span>
<span style="color: #003366; font-weight: bold;">function</span> getWeek<span style="color: #009900;">&#40;</span>y<span style="color: #339933;">,</span> m<span style="color: #339933;">,</span> d<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> _int <span style="color: #339933;">=</span> parseInt<span style="color: #339933;">,</span>
		c <span style="color: #339933;">=</span> _int<span style="color: #009900;">&#40;</span>y<span style="color: #339933;">/</span><span style="color: #CC0000;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	y <span style="color: #339933;">=</span> y.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	y <span style="color: #339933;">=</span> _int<span style="color: #009900;">&#40;</span>y<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: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>m <span style="color: #339933;">===</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		m <span style="color: #339933;">=</span> <span style="color: #CC0000;">13</span><span style="color: #339933;">;</span>
		y<span style="color: #339933;">--;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>m <span style="color: #339933;">===</span> <span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		m <span style="color: #339933;">=</span> <span style="color: #CC0000;">14</span><span style="color: #339933;">;</span>
		y<span style="color: #339933;">--;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> w <span style="color: #339933;">=</span> y <span style="color: #339933;">+</span> _int<span style="color: #009900;">&#40;</span>y<span style="color: #339933;">/</span><span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> _int<span style="color: #009900;">&#40;</span>c<span style="color: #339933;">/</span><span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">*</span>c <span style="color: #339933;">+</span> _int<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">26</span><span style="color: #339933;">*</span><span style="color: #009900;">&#40;</span>m<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> d <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
	w <span style="color: #339933;">=</span> w<span style="color: #339933;">%</span>7<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> w <span style="color: #339933;">&gt;=</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">?</span> w <span style="color: #339933;">:</span> w<span style="color: #339933;">+</span><span style="color: #CC0000;">7</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li><li>2010年11月22日 -- <a href="http://www.ihiro.org/text-range" title="Range:文本框选区学习笔记">Range:文本框选区学习笔记</a> (16)</li><li>2009年12月18日 -- <a href="http://www.ihiro.org/10-javascript-tips" title="Javascript:10个Javscript编程的技巧">Javascript:10个Javscript编程的技巧</a> (4)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2011年02月24日 -- <a href="http://www.ihiro.org/scroll-images" title="Javascript:图片无限循环滚动">Javascript:图片无限循环滚动</a> (27)</li><li>2010年11月25日 -- <a href="http://www.ihiro.org/css-position-hack" title="CSS:position属性定位总结">CSS:position属性定位总结</a> (28)</li><li>2010年11月3日 -- <a href="http://www.ihiro.org/html5-pro-ebook-recommendations" title="HTML5:《Pro HTML5 Programming》英文电子书推荐">HTML5:《Pro HTML5 Programming》英文电子书推荐</a> (21)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/javascript-getweek-by-date/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>CSS:position属性定位总结</title>
		<link>http://www.ihiro.org/css-position-hack</link>
		<comments>http://www.ihiro.org/css-position-hack#comments</comments>
		<pubDate>Thu, 25 Nov 2010 03:37:42 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[CSS、XHTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[总结笔记]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1568</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/11/position-logo.jpg" alt="" title="position-logo" width="100" height="100" class="alignleft size-full wp-image-1571" />
<p>在写这篇文章之前，我一直以为css中position定位时一直是读取最后出现两个方位属性的值。昨天给一同事演示jQuery的animate特效时，我试图通过js来控制已经设置过top和left的DIV的right属性为0，以达到滑动到最右边的效果。结果没有效果，很是郁闷。</p>
<p>早上写了一些关于postion的样式做测试，发现不论给某个DIV设置了多少个方位（当然最多到4个），也不管存放的顺序是如何颠倒，它的读取顺序依旧是top-bottom-left-right.很符合日常所说的“上下左右”规则。这与我之前理解的不相符合。</p>]]></description>
			<content:encoded><![CDATA[<p>在写这篇文章之前，我一直以为css中position定位时一直是读取最后出现两个方位属性的值。昨天给一同事演示jQuery的animate特效时，我试图通过js来控制已经设置过top和left的DIV的right属性为0，以达到滑动到最右边的效果。结果没有效果，很是郁闷。</p>
<p>早上写了一些关于postion的样式做测试，发现不论给某个DIV设置了多少个方位（当然最多到4个），也不管存放的顺序是如何颠倒，它的读取顺序依旧是top-bottom-left-right.很符合日常所说的“上下左右”规则。这与我之前理解的不相符合。</p>
<p>另外我们也知道给一个标签设置magin、padding、border等时，它的顺序是“上右下左”，这个顺序和方位读取顺序也没有类似的关系。为此我总结了一份Demo页面，供大家对比方位读取顺序，也算是一个总结笔记吧。</p>
<p class="demo-down-bar"><a target="_blank" href="http://www.ihiro.org/cases/position/position.zip" rel="external" class="download">download</a> <a target="_blank" href="http://www.ihiro.org/cases/position/" rel="external" class="demo">demo</a></p>
<p class="green"><strong>附文中jQuery的animate示例：</strong></p>
<h3>Html代码：</h3>

<div class="wp_codebox"><table><tr id="p156841"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p1568code41"><pre class="html" style="font-family:monospace;">&lt;button id=&quot;trigger&quot;&gt;Click To Animate&lt;/button&gt;
&lt;div id=&quot;box&quot;&gt;
	&lt;div class=&quot;box&quot; id=&quot;box1&quot;&gt;&lt;/div&gt;
	&lt;div class=&quot;box&quot; id=&quot;box2&quot;&gt;&lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<h3>CSS代码：</h3>

<div class="wp_codebox"><table><tr id="p156842"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1568code42"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#box</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">800px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">dashed</span> <span style="color: #cc00cc;">#eee</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.box</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">120px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#f60</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#390</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#box1</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#box2</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">62px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>jQuery代码：</h3>

<div class="wp_codebox"><table><tr id="p156843"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1568code43"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#trigger'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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: #009900;">&#40;</span><span style="color: #3366CC;">'.box'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'right'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'0'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>结果执行JS后，Firebug中实时Html代码为：<a href="http://www.ihiro.org/blog/wp-content/uploads/2010/11/firebug-code.jpg"><img src="http://www.ihiro.org/blog/wp-content/uploads/2010/11/firebug-code.jpg" alt="" title="firebug-code" width="494" height="59" class="aligncenter size-full wp-image-1570" /></a>而通过Cssviewer观察到的代码不变：<a href="http://www.ihiro.org/blog/wp-content/uploads/2010/11/cssviewer-code.jpg"><img src="http://www.ihiro.org/blog/wp-content/uploads/2010/11/cssviewer-code.jpg" alt="" title="cssviewer-code" width="284" height="147" class="aligncenter size-full wp-image-1569" /></a></p>
<p class="red">所以，不要试图用JS来改变已设定top和left的DIV的right和bottom值，当然改变top和left值还是会有效果出来的。</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年03月8日 -- <a href="http://www.ihiro.org/css3-basic" title="CSS:CSS3基础（附图）">CSS:CSS3基础（附图）</a> (12)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li><li>2011年03月2日 -- <a href="http://www.ihiro.org/css-specific-for-internet-explorer" title="CSS:区分IE版本的三个方法">CSS:区分IE版本的三个方法</a> (27)</li><li>2010年12月30日 -- <a href="http://www.ihiro.org/javascript-getweek-by-date" title="Javascript:根据指定日期获得星期数">Javascript:根据指定日期获得星期数</a> (23)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/css-position-hack/feed</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Range:文本框选区学习笔记</title>
		<link>http://www.ihiro.org/text-range</link>
		<comments>http://www.ihiro.org/text-range#comments</comments>
		<pubDate>Mon, 22 Nov 2010 05:38:30 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[Pure Javascript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Range]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[学习笔记]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1556</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/11/text-range.jpg" alt="" title="text-range" width="100" height="100" class="alignleft size-full wp-image-1557" />
<p>有一段时间没有看《Javascript高级程序设计》了，最近重新接着看起，发现新的两个勘误，已经提交给<a href="http://www.cn-cuckoo.com/" rel="external">为之漫笔</a>了。</p>
<p>昨晚看到了文本框选区跨浏览器处理的部分。之前参加的交流会上，Taobao的前端分享过他们的Editor，主要的技术也是Range的应用。Range主要还是用在即见即所得Editor中，本文纯粹是做笔记之用，为避免以后自己遇到这样的需求而到处搜索，不如在自己的Blog上做个标记。</p>
<p>也做了个Demo页面，有兴趣的可以点击了查看效果。</p>]]></description>
			<content:encoded><![CDATA[<p>有一段时间没有看《Javascript高级程序设计》了，最近重新接着看起，发现新的两个勘误，已经提交给<a href="http://www.cn-cuckoo.com/" rel="external">为之漫笔</a>了。</p>
<p>昨晚看到了文本框选区跨浏览器处理的部分。之前参加的交流会上，Taobao的前端分享过他们的Editor，主要的技术也是Range的应用。Range主要还是用在即见即所得Editor中，本文纯粹是做笔记之用，为避免以后自己遇到这样的需求而到处搜索，不如在自己的Blog上做个标记。</p>
<p>也做了个Demo页面，有兴趣的可以点击了查看效果。</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/textRange/textRange.zip" rel="external" class="download">download</a> <a href="http://www.ihiro.org/cases/textRange/" rel="external" class="demo">demo</a></p>
<h3>一、Html代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p155644"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p1556code44"><pre class="html" style="font-family:monospace;">&lt;ul&gt;
	&lt;li&gt;&lt;input type=&quot;text&quot; value=&quot;Hello World!&quot; id=&quot;textbox&quot; name=&quot;textbox&quot; size=&quot;50&quot; /&gt;&lt;/li&gt;
&nbsp;
    &lt;li&gt;&lt;input type=&quot;button&quot; id=&quot;getSelectedBtn&quot; value=&quot;getSelectedText&quot; /&gt;&lt;/li&gt;
&nbsp;
    &lt;li&gt;&lt;label for=&quot;startIndex&quot;&gt;开始位置：&lt;/label&gt;&lt;input type=&quot;text&quot; size=&quot;5&quot; id=&quot;startIndex&quot; name=&quot;startIndex&quot; /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;label for=&quot;stopIndex&quot;&gt;结束位置：&lt;/label&gt;&lt;input type=&quot;text&quot; size=&quot;5&quot; id=&quot;stopIndex&quot; name=&quot;endIndex&quot; /&gt;&lt;/li&gt;
&nbsp;
	&lt;li&gt;&lt;input type=&quot;button&quot; id=&quot;selectBtn&quot; value=&quot;selectText&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;</pre></td></tr></table></div>

</p>
<h3>二、Javascript代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p155645"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code" id="p1556code45"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> textbox <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'textbox'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	getSelectedBtn <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'getSelectedBtn'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	selectBtn <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'selectBtn'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> getSelectedText<span style="color: #009900;">&#40;</span>textbox<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>document.<span style="color: #660066;">selection</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> document.<span style="color: #660066;">selection</span>.<span style="color: #660066;">createRange</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//IE</span>
		<span style="color: #000066; font-weight: bold;">return</span> textbox.<span style="color: #660066;">value</span>.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>textbox.<span style="color: #660066;">selectionStart</span><span style="color: #339933;">,</span> textbox.<span style="color: #660066;">selectionEnd</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>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> selectText<span style="color: #009900;">&#40;</span>textbox<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> startIndex <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'startIndex'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">,</span> 
		stopIndex <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'stopIndex'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>textbox.<span style="color: #660066;">setSelectionRange</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		textbox.<span style="color: #660066;">setSelectionRange</span><span style="color: #009900;">&#40;</span>startIndex<span style="color: #339933;">,</span> stopIndex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>textbox.<span style="color: #660066;">createTextRange</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//IE</span>
		<span style="color: #003366; font-weight: bold;">var</span> range <span style="color: #339933;">=</span> textbox.<span style="color: #660066;">createTextRange</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #006600; font-style: italic;">//创建范围</span>
		range.<span style="color: #660066;">collapse</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>				<span style="color: #006600; font-style: italic;">//折叠预选取范围到开始位置</span>
		range.<span style="color: #660066;">moveStart</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'character'</span><span style="color: #339933;">,</span> startIndex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #006600; font-style: italic;">//将预选取范围的起点和终点移动到相同的位置</span>
		range.<span style="color: #660066;">moveEnd</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'character'</span><span style="color: #339933;">,</span> stopIndex <span style="color: #339933;">-</span> startIndex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #006600; font-style: italic;">//选取字符长度</span>
		range.<span style="color: #660066;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			<span style="color: #006600; font-style: italic;">//选取范围</span>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>stopIndex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	textbox.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
getSelectedBtn.<span style="color: #660066;">onclick</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>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>getSelectedText<span style="color: #009900;">&#40;</span>textbox<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
selectBtn.<span style="color: #660066;">onclick</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>
	selectText<span style="color: #009900;">&#40;</span>textbox<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2010年12月30日 -- <a href="http://www.ihiro.org/javascript-getweek-by-date" title="Javascript:根据指定日期获得星期数">Javascript:根据指定日期获得星期数</a> (23)</li><li>2009年12月18日 -- <a href="http://www.ihiro.org/10-javascript-tips" title="Javascript:10个Javscript编程的技巧">Javascript:10个Javscript编程的技巧</a> (4)</li><li>2009年09月10日 -- <a href="http://www.ihiro.org/javascript-oop" title="Javascript:面向对象之静态、公有、私有、特权对象">Javascript:面向对象之静态、公有、私有、特权对象</a> (10)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2011年02月24日 -- <a href="http://www.ihiro.org/scroll-images" title="Javascript:图片无限循环滚动">Javascript:图片无限循环滚动</a> (27)</li><li>2010年11月25日 -- <a href="http://www.ihiro.org/css-position-hack" title="CSS:position属性定位总结">CSS:position属性定位总结</a> (28)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/text-range/feed</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>jQuery:热区高亮maphighlight插件推荐</title>
		<link>http://www.ihiro.org/jquery-plugin-recommended-maphighlight</link>
		<comments>http://www.ihiro.org/jquery-plugin-recommended-maphighlight#comments</comments>
		<pubDate>Thu, 21 Oct 2010 01:36:04 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[插件收集]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[推荐]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1543</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/10/maohightlight-logo.jpg" alt="" title="maohightlight-logo" width="100" height="100" class="alignleft size-full wp-image-1546" />
<p>上月的一个韩国项目，客户要求首页的图片热点区域高亮。开始我的思路是使用div层，效果也实现了，但因为热点区域是不规则形状，而div层却是很规整的原因。结果这个设想被推翻了。</p>
<p>接着我就试图去搜索一些相关全区高亮的资料，结果就让我搜到了maphighlight插件。基于jQeury库，结合了最新的HTML5的Canvas画布标签，通过绘画的方式实现了热点区域的高亮。</p>
<p>因项目还没上线（已结束），所以我的实现效果就不做公布了！</p>]]></description>
			<content:encoded><![CDATA[<p>上月的一个韩国项目，客户要求首页的图片热点区域高亮。开始我的思路是使用div层，效果也实现了，但因为热点区域是不规则形状，而div层却是很规整的原因。结果这个设想被推翻了。</p>
<p>接着我就试图去搜索一些相关全区高亮的资料，结果就让我搜到了maphighlight插件。基于jQeury库，结合了最新的HTML5的Canvas画布标签，通过绘画的方式实现了热点区域的高亮。</p>
<p>因项目还没上线（已结束），所以我的实现效果就不做公布了！</p>
<h3>一、原理：</h3>
<p>其实maohighlight插件的实现原理很简单，在图片的基础上建立一个同等尺寸的Canvas标签，通过坐标点coords画出不规则的线。关键的技术难点是对Canvas的各个画图方法的了解和应用！</p>
<p>至于精准的选取坐标可以通过Fireworks软件在图片上选取出来，然后将图片另存为Html页面格式，在源代码里即可看到选取的坐标。</p>
<h3>二、Demo：</h3>
<p>示例截图：<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/10/maohightlight.jpg" alt="" title="maohightlight" width="600" height="298" class="aligncenter size-full wp-image-1545" /></p>
<ol class="ol_with_num">
<li><a href="http://davidlynch.org/js/maphilight/docs/demo_simple.html" rel="external">简单示例</a></li>
<li><a href="http://davidlynch.org/js/maphilight/docs/demo_world.html" rel="external">世界地图</a></li>
<li><a href="http://davidlynch.org/js/maphilight/docs/demo_usa.html" rel="external">美国地图</a></li>
<li><a href="http://davidlynch.org/js/maphilight/docs/demo_features.html" rel="external">特性示例</a></li>
</ol>
<h3>三、文档：</h3>
<p>使用很简单，也可以自定义选取色彩等效果，更多请阅读官方文档：<a href="http://davidlynch.org/js/maphilight/docs/" rel="external">http://davidlynch.org/js/maphilight/docs/</a></p>
<h3>四、代码版本：</h3>
<p><a href="http://github.com/kemayo/maphilight/" rel="external">http://github.com/kemayo/maphilight/</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年06月30日 -- <a href="http://www.ihiro.org/firebug-console-panel-function" title="Firebug:Javascript测试利器，Console面板函数详解">Firebug:Javascript测试利器，Console面板函数详解</a> (4)</li><li>2010年02月24日 -- <a href="http://www.ihiro.org/javascript-news-flash-header-tips" title="Javascript:新消息闪烁标题提示代码分享">Javascript:新消息闪烁标题提示代码分享</a> (7)</li><li>2009年11月2日 -- <a href="http://www.ihiro.org/my-first-plugin-scrolltop" title="插件:我的第一个插件&#8211;简约的scrollTop滑动插件">插件:我的第一个插件&#8211;简约的scrollTop滑动插件</a> (23)</li><li>2009年08月21日 -- <a href="http://www.ihiro.org/jquery-scrolltop-plugins" title="jQuery:Scrolltop滑动插件推荐（修正注释版）">jQuery:Scrolltop滑动插件推荐（修正注释版）</a> (25)</li><li>2009年06月18日 -- <a href="http://www.ihiro.org/jquery-plugins-for-dw4" title="jQuery plugins for DW4">jQuery plugins for DW4</a> (2)</li><li>2011年11月25日 -- <a href="http://www.ihiro.org/firebug-extension-firequery" title="插件：Firebug扩展插件FireQuery">插件：Firebug扩展插件FireQuery</a> (2)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年08月12日 -- <a href="http://www.ihiro.org/sizzle-custom-selector" title="Sizzle:开源JS选择器，如何自定义选择器">Sizzle:开源JS选择器，如何自定义选择器</a> (31)</li><li>2010年05月21日 -- <a href="http://www.ihiro.org/dw-html5-extension" title="扩展:Adobe放出Dreamweaver CS5 HTML 5扩展包">扩展:Adobe放出Dreamweaver CS5 HTML 5扩展包</a> (16)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/jquery-plugin-recommended-maphighlight/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>jQuery:数字、字符串格式化扩展</title>
		<link>http://www.ihiro.org/jquery-format-extend</link>
		<comments>http://www.ihiro.org/jquery-format-extend#comments</comments>
		<pubDate>Mon, 20 Sep 2010 01:43:26 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1525</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/09/jQuery.format_logo.png" alt="" title="jQuery.format_logo" width="107" height="103" class="alignleft size-full wp-image-1526" />
<p>前几天的项目中，遇到一个格式化金额的问题，便写了一个通用的jQuery扩展代码，记录下来以便以后再用。同时分享给大家，有需要的随便用。</p>
<p>若有高手觉得写得有效率问题的也可以提出来，学习学习，研究研究。</p>
<p>除了数字外，字符串也可以格式化的，毕竟实现起来原理差不多嘛！可以自定义分隔符、分割长度，最终返回的格式化后的字符串。</p>]]></description>
			<content:encoded><![CDATA[<p>前几天的项目中，遇到一个格式化金额的问题，便写了一个通用的jQuery扩展代码，记录下来以便以后再用。同时分享给大家，有需要的随便用。</p>
<p>若有高手觉得写得有效率问题的也可以提出来，学习学习，研究研究。</p>
<p>除了数字外，字符串也可以格式化的，毕竟实现起来原理差不多嘛！可以自定义分隔符、分割长度，最终返回的格式化后的字符串。</p>
<h3>一、jQuery扩展代码</h3>
<p>
<div class="wp_codebox"><table><tr id="p152546"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code" id="p1525code46"><pre class="javascript" style="font-family:monospace;"><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: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		format <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> step<span style="color: #339933;">,</span> splitor<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			str <span style="color: #339933;">=</span> str.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> len <span style="color: #339933;">=</span> str.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>len <span style="color: #339933;">&gt;</span> step<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				 <span style="color: #003366; font-weight: bold;">var</span> l1 <span style="color: #339933;">=</span> len<span style="color: #339933;">%</span>step<span style="color: #339933;">,</span> 
					 l2 <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>len<span style="color: #339933;">/</span>step<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
					 arr <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
					 first <span style="color: #339933;">=</span> str.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> l1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				 <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>first <span style="color: #339933;">!=</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					 arr.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>first<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;">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>l2 <span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					 arr.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>str.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span>l1 <span style="color: #339933;">+</span> i<span style="color: #339933;">*</span>step<span style="color: #339933;">,</span> step<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>									 
				 <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
				 str <span style="color: #339933;">=</span> arr.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span>splitor<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;">return</span> str<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p></l2></pre>
</p>
<h3>二、调用方法</h3>
<p>
<div class="wp_codebox"><table><tr id="p152547"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1525code47"><pre class="javascript" style="font-family:monospace;">jQuery<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>
	console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">format</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2000000010</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</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>		<span style="color: #006600; font-style: italic;">//result:	2,000,000,010</span>
	console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">format</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'abcdefghijklmnopqrstuvwxyz'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">6</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>	<span style="color: #006600; font-style: italic;">//result:	ab-cdefgh-ijklmn-opqrst-uvwxyz</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li><li>2010年02月24日 -- <a href="http://www.ihiro.org/javascript-news-flash-header-tips" title="Javascript:新消息闪烁标题提示代码分享">Javascript:新消息闪烁标题提示代码分享</a> (7)</li><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li><li>2011年02月24日 -- <a href="http://www.ihiro.org/scroll-images" title="Javascript:图片无限循环滚动">Javascript:图片无限循环滚动</a> (27)</li><li>2010年12月30日 -- <a href="http://www.ihiro.org/javascript-getweek-by-date" title="Javascript:根据指定日期获得星期数">Javascript:根据指定日期获得星期数</a> (23)</li><li>2010年11月22日 -- <a href="http://www.ihiro.org/text-range" title="Range:文本框选区学习笔记">Range:文本框选区学习笔记</a> (16)</li><li>2010年10月21日 -- <a href="http://www.ihiro.org/jquery-plugin-recommended-maphighlight" title="jQuery:热区高亮maphighlight插件推荐">jQuery:热区高亮maphighlight插件推荐</a> (23)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/jquery-format-extend/feed</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>示例:Selectbox模拟实现效果</title>
		<link>http://www.ihiro.org/example-selectbox-simulation</link>
		<comments>http://www.ihiro.org/example-selectbox-simulation#comments</comments>
		<pubDate>Thu, 02 Sep 2010 15:07:01 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[CSS、XHTML]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Cases]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1514</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/09/select_logo.png" alt="" title="select_logo" width="100" height="100" class="alignleft size-full wp-image-1515" />
<p>很长时间没有更新了，也很久没有做实例分享了。最近比较动荡，也比较忙，所以博客的更新频率也变了。</p>
<p>今天的实例算是很小的了吧，是在之前公司的公司网上做的效果，今天朋友让我扣出来给他。我便做了份，整理了分享出来给大家参考。</p>
<p>近期因新工作需要，在学习XML和XSLT相关的知识，以后也会在博客中记录一些学习笔记！</p>]]></description>
			<content:encoded><![CDATA[<p>很长时间没有更新了，也很久没有做实例分享了。最近比较动荡，也比较忙，所以博客的更新频率也变了。</p>
<p>今天的实例算是很小的了吧，是在之前公司的公司网上做的效果，今天朋友让我扣出来给他。我便做了份，整理了分享出来给大家参考。</p>
<p>近期因新工作需要，在学习XML和XSLT相关的知识，以后也会在博客中记录一些学习笔记！</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/selectbox/selectbox.rar" class="download">download</a> <a href="http://www.ihiro.org/cases/selectbox/" rel="external" class="demo">demo</a></p>
<h3>一、HTML代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p151448"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p1514code48"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;selectBox&quot;&gt;
    &lt;div id=&quot;cats_seltor&quot;&gt;&lt;span&gt;全部&lt;/span&gt;&lt;em&gt;&lt;/em&gt;&lt;/div&gt;
    &lt;dl id=&quot;cats_lks&quot;&gt;
        &lt;dd&gt;&lt;a href=&quot;#all_svys&quot;&gt;全部&lt;/a&gt;&lt;/dd&gt;
        &lt;dd&gt;&lt;a href=&quot;#social_svys&quot;&gt;社会&lt;/a&gt;&lt;/dd&gt;
        &lt;dd&gt;&lt;a href=&quot;#emotion_svys&quot;&gt;情感&lt;/a&gt;&lt;/dd&gt;
        &lt;dd&gt;&lt;a href=&quot;#product_svys&quot;&gt;产品&lt;/a&gt;&lt;/dd&gt;
        &lt;dd&gt;&lt;a href=&quot;#happiness_svys&quot;&gt;开心&lt;/a&gt;&lt;/dd&gt;
        &lt;dd&gt;&lt;a href=&quot;#literary_svys&quot;&gt;文体&lt;/a&gt;&lt;/dd&gt;
        &lt;dd&gt;&lt;a href=&quot;#finance_svys&quot;&gt;财经&lt;/a&gt;&lt;/dd&gt;
        &lt;dd&gt;&lt;a href=&quot;#tech_svys&quot;&gt;科技&lt;/a&gt;&lt;/dd&gt;
        &lt;dd&gt;&lt;a href=&quot;#point_svys&quot;&gt;点子俱乐部&lt;/a&gt;&lt;/dd&gt;
    &lt;/dl&gt;
&lt;/div&gt;</pre></td></tr></table></div>

</p>
<h3>二、CSS代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p151449"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p1514code49"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span> Verdana<span style="color: #00AA00;">,</span> Geneva<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#selectBox</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">116px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#cats_seltor</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">22px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#cats_seltor</span> span<span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#cats_seltor</span> em <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#cats_seltor</span> span <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#d4d5d8</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">74px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f60</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#cats_seltor</span> em <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">22px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">arrow.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#cats_seltor</span> em<span style="color: #6666ff;">.down</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">-30px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#cats_lks</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">114px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#d4d5d8</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-top</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">22px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">10</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#cats_lks</span> dd <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span> <span style="color: #933;">6px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#cats_lks</span> dd a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#666</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#cats_lks</span> dd a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f60</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</p>
<h3>三、jQuery代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p151450"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p1514code50"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;../js/jquery-1.4.2.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
jQuery<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: #009900;">&#40;</span><span style="color: #3366CC;">'#cats_seltor'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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: #009900;">&#40;</span><span style="color: #3366CC;">'em'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggleClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'down'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#cats_lks'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggle</span><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;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#cats_lks a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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> _text <span style="color: #339933;">=</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: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#cats_lks'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#cats_seltor'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>_text<span style="color: #009900;">&#41;</span>
					.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'em'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'down'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>
</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2009年08月28日 -- <a href="http://www.ihiro.org/jquery-hot-pictures-showing-effects-of-rotation" title="jQuery:热点图片轮换展示效果">jQuery:热点图片轮换展示效果</a> (14)</li><li>2009年07月14日 -- <a href="http://www.ihiro.org/keyboard-simulation-with-css-and-jquery" title="jQuery:使用css+jQuery模拟键盘">jQuery:使用css+jQuery模拟键盘</a> (10)</li><li>2009年07月10日 -- <a href="http://www.ihiro.org/the-effection-of-books-show" title="jQuery:书籍展示效果">jQuery:书籍展示效果</a> (6)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/the-effection-of-tab-like-msn" title="jQuery:仿MSN网站的tab效果">jQuery:仿MSN网站的tab效果</a> (30)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/a-simple-6-lines-of-code-to-achieve-the-tab-effecttion" title="jQuery：简单6行代码实现tab效果">jQuery：简单6行代码实现tab效果</a> (10)</li><li>2009年06月30日 -- <a href="http://www.ihiro.org/the-effection-of-thunder-home-page" title="jQuery：仿迅雷首页热片滑动效果">jQuery：仿迅雷首页热片滑动效果</a> (6)</li><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年07月6日 -- <a href="http://www.ihiro.org/pure-css-dynamic-page-effects" title="CSS:纯css的伪动态分页效果">CSS:纯css的伪动态分页效果</a> (17)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/example-selectbox-simulation/feed</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Sizzle:开源JS选择器，如何自定义选择器</title>
		<link>http://www.ihiro.org/sizzle-custom-selector</link>
		<comments>http://www.ihiro.org/sizzle-custom-selector#comments</comments>
		<pubDate>Thu, 12 Aug 2010 03:12:32 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Selector]]></category>
		<category><![CDATA[Sizzle]]></category>
		<category><![CDATA[开源]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1500</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/08/Sizzle_logo.png" alt="" title="Sizzle_logo" width="100" height="100" class="alignleft size-full wp-image-1506" />
<p>早上看了<a href="http://www.baiduux.com/blog/" rel="external">百度泛用户体验</a>博客的博文<a href="http://www.baiduux.com/blog/2010/07/15/the_sizzle_in_jquery/" rel="external">初探 jQuery 的 Sizzle 选择器</a>，让我对Sizzle选择器的知识又更加地深入了解。之前我就知道jQuery中有一个开源的Sizzle选择器程序，可以独立于jQuery单独使用。而在jQuery中使用到的各种强大的选择器都是通过Sizzle来解析返回值的。</p>
<p>Sizzle代码及注册; ':header'的用处; 如何自定义选择器; Sizzle选择器流程图</p>
<p>John很强大，感谢他让我学习到如此美妙和优雅的代码。</p>]]></description>
			<content:encoded><![CDATA[<p>早上看了<a href="http://www.baiduux.com/blog/" rel="external">百度泛用户体验</a>博客的博文<a href="http://www.baiduux.com/blog/2010/07/15/the_sizzle_in_jquery/" rel="external">初探 jQuery 的 Sizzle 选择器</a>，让我对Sizzle选择器的知识又更加地深入了解。之前我就知道jQuery中有一个开源的Sizzle选择器程序，可以独立于jQuery单独使用。而在jQuery中使用到的各种强大的选择器都是通过Sizzle来解析返回值的。</p>
<h3>一、Sizzle代码及注册：</h3>
<p>在jQuery1.42版本中，Sizzle代码位于 2624行 至 3688行。相比单独的Sizzle.js，在jQuery框架中多了几行代码，将Sizzle注册到jQuery中：<br />
<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/08/expose_sizzle_in_jquery.jpg" alt="" title="expose_sizzle_in_jquery" width="341" height="145" class="aligncenter size-full wp-image-1501" /><br />
单独的Sizzle.js可以到Github:<a href="http://github.com/jeresig/sizzle/blob/master/sizzle.js" rel="external">http://github.com/jeresig/sizzle/blob/master/sizzle.js</a>查看。</p>
<h3>二、&#8217;:header&#8217;的用处：</h3>
<p>就在我阅读Sizzle.js的源代码时，发现了&#8217;:header&#8217;选择器，代码如下（位于3132-3134行）：</p>

<div class="wp_codebox"><table><tr id="p150051"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1500code51"><pre class="javascript" style="font-family:monospace;">		header<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>elem<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009966; font-style: italic;">/h\d/i</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> elem.<span style="color: #660066;">nodeName</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>这个选择器在正常的CHM API文档中没有给出，估计大家也很少用到过（我自己就没用过）。它的用处是匹配（h1-h6)标题标签，知道有这个选择器了，以后工作中也要多多应用才是。<br />
<br />使用方法：</p>

<div class="wp_codebox"><table><tr id="p150052"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1500code52"><pre class="javascript" style="font-family:monospace;">		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':header'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'...'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>更多&#8217;:header&#8217;相关请阅读：<a href="http://api.jquery.com/header-selector/" rel="external">http://api.jquery.com/header-selector/</a>
</p>
<h3>三、如何自定义选择器：</h3>
<p>Sizzle中给出了很多的选择器，那么我们也可以自己定义自己所需的选择器，代码如下：<br />
<br />html实例代码：</p>

<div class="wp_codebox"><table><tr id="p150053"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1500code53"><pre class="html" style="font-family:monospace;">    &lt;div id=&quot;box&quot;&gt;
    	&lt;span&gt;找到我&lt;/span&gt;
    &lt;/div&gt;</pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p150054"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p1500code54"><pre class="javascript" style="font-family:monospace;">	jQuery<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: #660066;">extend</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">expr</span><span style="color: #009900;">&#91;</span><span style="color: #3366CC;">':'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
			hasSpan <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#box:hasSpan'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #006600; font-style: italic;">//输出：&lt;span&gt;找到我&lt;/span&gt;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>四、附上百度博客的Sizzle选择器流程图：</h3>
<p>点击查看大图：<br />
<a href="http://www.ihiro.org/blog/wp-content/uploads/2010/08/sizzle_flow1.jpg" rel="external"><img src="http://www.ihiro.org/blog/wp-content/uploads/2010/08/sizzle_flow1.jpg" alt="" title="sizzle_flow" width="600" height="304" class="aligncenter wp-image-1505" /></a></p>
<p>John很强大，感谢他让我学习到如此美妙和优雅的代码。</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2009年07月14日 -- <a href="http://www.ihiro.org/keyboard-simulation-with-css-and-jquery" title="jQuery:使用css+jQuery模拟键盘">jQuery:使用css+jQuery模拟键盘</a> (10)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li><li>2010年11月22日 -- <a href="http://www.ihiro.org/text-range" title="Range:文本框选区学习笔记">Range:文本框选区学习笔记</a> (16)</li><li>2010年10月21日 -- <a href="http://www.ihiro.org/jquery-plugin-recommended-maphighlight" title="jQuery:热区高亮maphighlight插件推荐">jQuery:热区高亮maphighlight插件推荐</a> (23)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年06月30日 -- <a href="http://www.ihiro.org/firebug-console-panel-function" title="Firebug:Javascript测试利器，Console面板函数详解">Firebug:Javascript测试利器，Console面板函数详解</a> (4)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/sizzle-custom-selector/feed</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Firebug:Javascript测试利器，Console面板函数详解</title>
		<link>http://www.ihiro.org/firebug-console-panel-function</link>
		<comments>http://www.ihiro.org/firebug-console-panel-function#comments</comments>
		<pubDate>Wed, 30 Jun 2010 06:22:34 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[前端工程]]></category>
		<category><![CDATA[Firebug]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[测试]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1472</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/06/Firebug_console.jpg" alt="" title="Firebug_console" width="100" height="100" class="alignleft size-full wp-image-1473" />
<p>从开始做前端时，一直在用火狐浏览器，之前也有文章介绍了一些火狐插件。今天重点来说说Firebug插件中的Console面板的功能，它可以辅助地完成Javascript性能测试和代码执行记录。</p>
<p>Console面板中自身含有多个可供使用的函数，诸如：console.log(),console.time()等一些常用的方法，我的想法是将这些函数写入在jQuery插件中，这样在项目的前端开发和测试阶段使用起来非常地方便。</p>
<p class="red">代码执行后的效果需要打开Console面板后才可以看到，若出现错误提示，不要惊慌，那是因为使用console.error()方法抛出错误所致，页面的代码并没有出错！</p>]]></description>
			<content:encoded><![CDATA[<p>从开始做前端时，一直在用火狐浏览器，之前也有文章介绍了一些火狐插件。今天重点来说说Firebug插件中的Console面板的功能，它可以辅助地完成Javascript性能测试和代码执行记录。</p>
<p>Console面板中自身含有多个可供使用的函数，诸如：console.log(),console.time()等一些常用的方法，我的想法是将这些函数写入在jQuery插件中，这样在项目的前端开发和测试阶段使用起来非常地方便。</p>
<p class="red">代码执行后的效果需要打开Console面板后才可以看到，若出现错误提示，不要惊慌，那是因为使用console.error()方法抛出错误所致，页面的代码并没有出错！</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/Firebug_Console/Firebug_Console.rar" class="download">download</a> <a target="_blank" href="http://www.ihiro.org/cases/Firebug_Console/" rel="external" class="demo">demo</a></p>
<p>下面的代码是将Console面板中的大部分比较常用的函数扩展到jQuery的fn对象中，作为一个插件，它的实现原理和使用都很方便。</p>
<h3>一、插件代码：</h3>

<div class="wp_codebox"><table><tr id="p147255"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code" id="p1472code55"><pre class="javascript" style="font-family:monospace;">	jQuery<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: #660066;">fn</span>.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			log <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>typeIndex<span style="color: #339933;">,</span> msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>typeIndex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">:</span>
						console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">:</span>
						console.<span style="color: #660066;">debug</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">:</span>
						console.<span style="color: #660066;">info</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">:</span>
						console.<span style="color: #660066;">warn</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
					<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">:</span>
						console.<span style="color: #660066;">error</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000066; font-weight: bold;">break</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> 
&nbsp;
			timer <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>type<span style="color: #339933;">,</span> mark<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>type <span style="color: #339933;">==</span> <span style="color: #3366CC;">'start'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					console.<span style="color: #660066;">time</span><span style="color: #009900;">&#40;</span>mark<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>type <span style="color: #339933;">==</span> <span style="color: #3366CC;">'end'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					console.<span style="color: #660066;">timeEnd</span><span style="color: #009900;">&#40;</span>mark<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>
&nbsp;
			trace <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>
				console.<span style="color: #660066;">trace</span><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: #339933;">,</span>
&nbsp;
			group <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>type<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>type <span style="color: #339933;">==</span> <span style="color: #3366CC;">'start'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					console.<span style="color: #660066;">group</span><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: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>type <span style="color: #339933;">==</span> <span style="color: #3366CC;">'end'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					console.<span style="color: #660066;">groupEnd</span><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: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
			count <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>title<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				console.<span style="color: #660066;">count</span><span style="color: #009900;">&#40;</span>title<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
			dir <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				console.<span style="color: #660066;">dir</span><span style="color: #009900;">&#40;</span>object<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
			profile <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>type<span style="color: #339933;">,</span> title<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>type <span style="color: #339933;">==</span> <span style="color: #3366CC;">'start'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					console.<span style="color: #660066;">profile</span><span style="color: #009900;">&#40;</span>title<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>type <span style="color: #339933;">==</span> <span style="color: #3366CC;">'end'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					console.<span style="color: #660066;">profileEnd</span><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: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>二、测试页的Html代码：</h3>

<div class="wp_codebox"><table><tr id="p147256"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1472code56"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;demo&quot;&gt;&lt;/div&gt;</pre></td></tr></table></div>

<h3>三、测试页的调用代码：</h3>

<div class="wp_codebox"><table><tr id="p147257"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code" id="p1472code57"><pre class="javascript" style="font-family:monospace;">	jQuery<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> $container <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#demo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		$container.<span style="color: #660066;">profile</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'start'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'LoopAnchor'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//性能测试开始</span>
		$container.<span style="color: #660066;">timer</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'start'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Loop'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			<span style="color: #006600; font-style: italic;">//代码执行计时开始</span>
&nbsp;
		<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> <span style="color: #339933;">=</span><span style="color: #CC0000;">1000</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$container.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>$container.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>i<span style="color: #339933;">+</span><span style="color: #3366CC;">', '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$container.<span style="color: #660066;">count</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Loop count:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">%</span>100 <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				$container.<span style="color: #660066;">group</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'start'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>						<span style="color: #006600; font-style: italic;">//分组开始</span>
				<span style="color: #003366; font-weight: bold;">var</span> index <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		<span style="color: #006600; font-style: italic;">//根据不同序号，给出不同的记录方式	</span>
				$container.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>index<span style="color: #339933;">,</span> <span style="color: #3366CC;">'&lt;i%100==0&gt;: i='</span><span style="color: #339933;">+</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				$container.<span style="color: #660066;">trace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>								<span style="color: #006600; font-style: italic;">//追踪执行过程</span>
				$container.<span style="color: #660066;">group</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'end'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>						<span style="color: #006600; font-style: italic;">//分组结束</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		$container.<span style="color: #660066;">timer</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'end'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Loop'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			<span style="color: #006600; font-style: italic;">//代码执行计时结束</span>
		$container.<span style="color: #660066;">profile</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'end'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>					<span style="color: #006600; font-style: italic;">//性能测试结束</span>
&nbsp;
		$container.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span>Dir $.fn对象:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$container.<span style="color: #660066;">dir</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">fn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>			<span style="color: #006600; font-style: italic;">//列出jquery中fn对象的所有方法和属性</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p class="green">下载源压缩包的，记得引入jQuery库哦！</p>
<h3>附上Console面板函数列表图片一张：</h3>
<p><img src="http://www.ihiro.org/blog/wp-content/uploads/2010/06/Firebug_console_-func.jpg" alt="" title="Firebug_console_ func" width="534" height="1027" class="aligncenter size-full wp-image-1474" /></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年10月21日 -- <a href="http://www.ihiro.org/jquery-plugin-recommended-maphighlight" title="jQuery:热区高亮maphighlight插件推荐">jQuery:热区高亮maphighlight插件推荐</a> (23)</li><li>2010年02月24日 -- <a href="http://www.ihiro.org/javascript-news-flash-header-tips" title="Javascript:新消息闪烁标题提示代码分享">Javascript:新消息闪烁标题提示代码分享</a> (7)</li><li>2009年11月2日 -- <a href="http://www.ihiro.org/my-first-plugin-scrolltop" title="插件:我的第一个插件&#8211;简约的scrollTop滑动插件">插件:我的第一个插件&#8211;简约的scrollTop滑动插件</a> (23)</li><li>2009年08月21日 -- <a href="http://www.ihiro.org/jquery-scrolltop-plugins" title="jQuery:Scrolltop滑动插件推荐（修正注释版）">jQuery:Scrolltop滑动插件推荐（修正注释版）</a> (25)</li><li>2009年06月18日 -- <a href="http://www.ihiro.org/jquery-plugins-for-dw4" title="jQuery plugins for DW4">jQuery plugins for DW4</a> (2)</li><li>2011年11月25日 -- <a href="http://www.ihiro.org/firebug-extension-firequery" title="插件：Firebug扩展插件FireQuery">插件：Firebug扩展插件FireQuery</a> (2)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年08月12日 -- <a href="http://www.ihiro.org/sizzle-custom-selector" title="Sizzle:开源JS选择器，如何自定义选择器">Sizzle:开源JS选择器，如何自定义选择器</a> (31)</li><li>2010年05月21日 -- <a href="http://www.ihiro.org/dw-html5-extension" title="扩展:Adobe放出Dreamweaver CS5 HTML 5扩展包">扩展:Adobe放出Dreamweaver CS5 HTML 5扩展包</a> (16)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/firebug-console-panel-function/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CSS:Firefox 4 将支持CSS3 calc方法</title>
		<link>http://www.ihiro.org/firefox-4-will-support-css3-calc-method</link>
		<comments>http://www.ihiro.org/firefox-4-will-support-css3-calc-method#comments</comments>
		<pubDate>Sat, 12 Jun 2010 02:19:01 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[CSS、XHTML]]></category>
		<category><![CDATA[前端工程译文]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[业界信息]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1467</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/06/firefox-4-css3-calc.jpg" alt="" title="firefox-4-css3-calc" width="100" height="100" class="alignleft size-full wp-image-1468" />
<p>该文是用来讲解CSS3中calc()方法，这一功能特性在Firefox之前的任何版本中都没曾集成，但在Firefox4版本中它将得以实现。</p>
<p>Firefox将支持CSS3 calc()，它通过一个算术表达式用来计算出一个长度值。这就意味着你可以用它来定义DIVs的大小，margins的值，borders的宽度，等等。</p>
<p>一个重要的特性是：在calc()方法的算术表达式中可以联合多个不同的单位进行计算；calc()方法支持+, -, *, /, mod, min, 和 max 运算符。</p>
<p>资料参考来自：<a href="http://hacks.mozilla.org/2010/06/css3-calc/" rel="external">http://hacks.mozilla.org/2010/06/css3-calc/</a> &#124; <a href="http://www.w3.org/TR/css3-values/#calc" rel="external">http://www.w3.org/TR/css3-values/#calc</a></p>]]></description>
			<content:encoded><![CDATA[<p>该文是用来讲解CSS3中calc()方法，这一功能特性在Firefox之前的任何版本中都没曾集成，但在Firefox4版本中它将得以实现。</p>
<p>Firefox将支持CSS3 calc()，它通过一个算术表达式用来计算出一个长度值。这就意味着你可以用它来定义DIVs的大小，margins的值，borders的宽度，等等。</p>
<h3>一、calc(<expression>) </expression></h3>
<p>例子一：下面的例子用来展示一个棘手的布局问题，通过CSS3 calc()可以轻松实现：</p>

<div class="wp_codebox"><table><tr id="p146758"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p1467code58"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
* 两个DIVs对准，外间距为1em
*/</span>
<span style="color: #cc00cc;">#a</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">75%</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#b</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> -moz-calc<span style="color: #00AA00;">&#40;</span><span style="color: #933;">25%</span> - <span style="color: #933;">1em</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>不使用calc()的话，若通过百分比来控制宽度，并希望有1em外间距时，是无法实现的。当我们使用到外间距是，必须用页面宽度减去两个DIVs的宽度，这样的话就不够灵活了。
</p>
<p>例子二：通过calc()计算以保证一个input框的宽度不会超出其父标签的宽度：</p>

<div class="wp_codebox"><table><tr id="p146759"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p1467code59"><pre class="css" style="font-family:monospace;">input <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> -moz-calc<span style="color: #00AA00;">&#40;</span><span style="color: #933;">100%</span> - <span style="color: #cc66cc;">2</span> <span style="color: #00AA00;">*</span> <span style="color: #933;">3px</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</p>
<p>一个重要的特性是：在calc()方法的算术表达式中可以联合多个不同的单位进行计算：</p>

<div class="wp_codebox"><table><tr id="p146760"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1467code60"><pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> -moz-calc<span style="color: #00AA00;">&#40;</span><span style="color: #933;">3px</span> <span style="color: #00AA00;">+</span> <span style="color: #933;">50%</span>/<span style="color: #cc66cc;">3</span> - <span style="color: #933;">3em</span> <span style="color: #00AA00;">+</span> 1rem<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span></pre></td></tr></table></div>

</p>
<p>calc()方法支持+, -, *, /, mod, min, 和 max 运算符。</p>
<h3>二、min() | max()</h3>
<p>另外：Firefox4将也支持min() 和 max()方法，使用如下：</p>

<div class="wp_codebox"><table><tr id="p146761"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1467code61"><pre class="css" style="font-family:monospace;">div <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> -moz-min<span style="color: #00AA00;">&#40;</span><span style="color: #933;">36pt</span><span style="color: #00AA00;">,</span> <span style="color: #933;">2em</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> -moz-max<span style="color: #00AA00;">&#40;</span><span style="color: #933;">50%</span><span style="color: #00AA00;">,</span> <span style="color: #933;">18px</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</p>
<p>资料参考来自：<a href="http://hacks.mozilla.org/2010/06/css3-calc/" rel="external">http://hacks.mozilla.org/2010/06/css3-calc/</a> | <a href="http://www.w3.org/TR/css3-values/#calc" rel="external">http://www.w3.org/TR/css3-values/#calc</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年11月25日 -- <a href="http://www.ihiro.org/firebug-extension-firequery" title="插件：Firebug扩展插件FireQuery">插件：Firebug扩展插件FireQuery</a> (2)</li><li>2011年03月2日 -- <a href="http://www.ihiro.org/css-specific-for-internet-explorer" title="CSS:区分IE版本的三个方法">CSS:区分IE版本的三个方法</a> (27)</li><li>2010年11月25日 -- <a href="http://www.ihiro.org/css-position-hack" title="CSS:position属性定位总结">CSS:position属性定位总结</a> (28)</li><li>2010年09月13日 -- <a href="http://www.ihiro.org/information-september-2010-programming-language-list" title="资讯:2010年09月编程语言排行榜">资讯:2010年09月编程语言排行榜</a> (23)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年08月3日 -- <a href="http://www.ihiro.org/information-august-2010-programming-language-list" title="资讯:2010年08月编程语言排行榜">资讯:2010年08月编程语言排行榜</a> (12)</li><li>2010年07月9日 -- <a href="http://www.ihiro.org/information-july-2010-programming-language-list" title="资讯:2010年07月编程语言排行榜">资讯:2010年07月编程语言排行榜</a> (23)</li><li>2010年06月9日 -- <a href="http://www.ihiro.org/information-june-2010-programming-languages-list" title="资讯:2010年06月编程语言排行榜">资讯:2010年06月编程语言排行榜</a> (13)</li><li>2010年06月3日 -- <a href="http://www.ihiro.org/wordpress-3-new-features" title="Wordpress:3.0版本特性，将改变你的内容管理方式">Wordpress:3.0版本特性，将改变你的内容管理方式</a> (12)</li><li>2010年05月23日 -- <a href="http://www.ihiro.org/information-may-2010-programming-language-list" title="资讯:2010年05月编程语言排行榜">资讯:2010年05月编程语言排行榜</a> (23)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/firefox-4-will-support-css3-calc-method/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>CSS:通过一个样式表区分IE的各个版本</title>
		<link>http://www.ihiro.org/target-every-version-of-ie-from-a-single-stylesheet</link>
		<comments>http://www.ihiro.org/target-every-version-of-ie-from-a-single-stylesheet#comments</comments>
		<pubDate>Mon, 17 May 2010 07:47:40 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[CSS、XHTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[技巧]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1430</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/05/target-ie-version.jpg" alt="" title="target-ie-version" width="100" height="100" class="alignleft size-full wp-image-1431" />
<p>通常我们知道为了修复IE各个版本与其他浏览器的兼容，在head标签内会添加条件判断，根据不同的判断结果联入不同版本的CSS样式表。</p>
<p>这样的方法在我所有的网站或者博客中都是如此应用，但我也一直在纠结着多出了多余的样式表文件，HTTP请求也就多了一个。这对于我这个做前端的是一个严重的问题，但一直都没有找到可以优化的方法。</p>
<p>但是今天我看到了一篇文章，他教会了我另一种条件判断的方法。可以用条件判断的结果来添加多余的包含标签。同时也发现，自己思考的太少了。</p>]]></description>
			<content:encoded><![CDATA[<p>通常我们知道为了修复IE各个版本与其他浏览器的兼容，在head标签内会添加条件判断，根据不同的判断结果联入不同版本的CSS样式表。如下：</p>

<div class="wp_codebox"><table><tr id="p143062"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1430code62"><pre class="html" style="font-family:monospace;">&lt;!--[if IE 6]&gt;&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;ie6.css&quot; /&gt;&lt; ![endif]--&gt;
&lt;!--[if IE 7]&gt;&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;ie7.css&quot; /&gt;&lt; ![endif]--&gt;
&lt;!--[if IE 8]&gt;&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;ie8.css&quot; /&gt;&lt; ![endif]--&gt;</pre></td></tr></table></div>

</p>
<p>这样的方法在我所有的网站或者博客中都是如此应用，但我也一直在纠结着多出了多余的样式表文件，HTTP请求也就多了一个。这对于我这个做前端的是一个严重的问题，但一直都没有找到可以优化的方法。</p>
<p>但是今天我看到了一篇文章，他教会了我另一种条件判断的方法。可以用条件判断的结果来添加多余的包含标签。同时也发现，自己思考的太少了。实现方法如下：</p>

<div class="wp_codebox"><table><tr id="p143063"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p1430code63"><pre class="html" style="font-family:monospace;">&lt;!--[if IE 6]&gt;
	&lt;div id=&quot;ie6&quot;&gt;
&lt; ![endif]--&gt;
		&lt;div id=&quot;content&quot;&gt;
			&lt;div id=&quot;main&quot;&gt;&lt;/div&gt;
			&lt;div id=&quot;sidebar&quot;&gt;&lt;/div&gt;
		&lt;/div&gt;
		&lt;div id=&quot;footer&quot;&gt;&lt;/div&gt;
&lt;!--[if IE 6]&gt;
	&lt;/div&gt;
&lt; ![endif]--&gt;</pre></td></tr></table></div>

<p>通过这样的方法，我只需要一个样式表文件，然后在样式表中通过子选择器的方法来给出相应版本的css样式控制。如下：</p>

<div class="wp_codebox"><table><tr id="p143064"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1430code64"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#main</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">white</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#ie6</span> <span style="color: #cc00cc;">#main</span> <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</p>
<p>是不是你看到了也觉得惊奇呢，我就在感慨我怎么之前没有看到过这样的技巧文章了，发现原来该博主今天才更新了该文。我实在太幸运了，在我的新版主题里，我将采用这种区别IE版本的方法来控制css样式。</p>
<p class="red">追加一个Demo页面，大家可以通过IETester查看，不同版本下，样式是不一样的。</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/target-ie/target-ie.rar" class="download">download</a> <a href="http://www.ihiro.org/cases/target-ie/" rel="external" class="demo">demo</a></p>
<h3>Demo的css样式：</h3>

<div class="wp_codebox"><table><tr id="p143065"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p1430code65"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">24px</span> Tahoma<span style="color: #00AA00;">,</span> Geneva<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#666</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#main</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">400px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#eee</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#ie8</span> <span style="color: #cc00cc;">#main</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f00</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f60</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#9FF</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#ie7</span> <span style="color: #cc00cc;">#main</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#36F</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#009</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F0F</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#ie6</span> <span style="color: #cc00cc;">#main</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f60</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#090</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFC</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>Demo的Html源码：</h3>

<div class="wp_codebox"><table><tr id="p143066"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p1430code66"><pre class="html" style="font-family:monospace;">&lt;!--[if IE 8]&gt;
	&lt;div id=&quot;ie8&quot;&gt;
&lt; ![endif]--&gt;
&lt;!--[if IE 7]&gt;
	&lt;div id=&quot;ie7&quot;&gt;
&lt; ![endif]--&gt;
&lt;!--[if IE 6]&gt;
	&lt;div id=&quot;ie6&quot;&gt;
&lt; ![endif]--&gt;
&nbsp;
	&lt;div id=&quot;main&quot;&gt;Target-IE-Version&lt;/div&gt;
&nbsp;
&lt;!--[if IE 6]&gt;
	&lt;/div&gt;
&lt; ![endif]--&gt;
&lt;!--[if IE 7]&gt;
	&lt;/div&gt;
&lt; ![endif]--&gt;
&lt;!--[if IE 8]&gt;
	&lt;/div&gt;
&lt; ![endif]--&gt;</pre></td></tr></table></div>

<p>该技巧学习自文章：<a href="http://jscariati.wordpress.com/2010/05/16/target-every-version-of-ie-from-a-single-stylesheet/" rel="external">Target Every Version of IE from a Single Stylesheet</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年03月2日 -- <a href="http://www.ihiro.org/css-specific-for-internet-explorer" title="CSS:区分IE版本的三个方法">CSS:区分IE版本的三个方法</a> (27)</li><li>2009年09月3日 -- <a href="http://www.ihiro.org/share-some-common-techniques-of-css" title="CSS:分享一些常用的css技巧">CSS:分享一些常用的css技巧</a> (8)</li><li>2010年11月25日 -- <a href="http://www.ihiro.org/css-position-hack" title="CSS:position属性定位总结">CSS:position属性定位总结</a> (28)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年06月12日 -- <a href="http://www.ihiro.org/firefox-4-will-support-css3-calc-method" title="CSS:Firefox 4 将支持CSS3 calc方法">CSS:Firefox 4 将支持CSS3 calc方法</a> (18)</li><li>2010年03月8日 -- <a href="http://www.ihiro.org/css3-basic" title="CSS:CSS3基础（附图）">CSS:CSS3基础（附图）</a> (12)</li><li>2010年02月20日 -- <a href="http://www.ihiro.org/how-to-insert-googlebuzz-data-into-blog" title="Wordpress:如何将GoogleBuzz数据插入到博客中">Wordpress:如何将GoogleBuzz数据插入到博客中</a> (11)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年09月16日 -- <a href="http://www.ihiro.org/including-wordpress-comment-reply-js" title="Wordpress:正确地引入comment-reply.js文件">Wordpress:正确地引入comment-reply.js文件</a> (24)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/target-every-version-of-ie-from-a-single-stylesheet/feed</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>jQuery:揭露jQuery的隐藏功能</title>
		<link>http://www.ihiro.org/uncovering-jquerys-hidden-features</link>
		<comments>http://www.ihiro.org/uncovering-jquerys-hidden-features#comments</comments>
		<pubDate>Mon, 15 Mar 2010 05:43:30 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[前端工程译文]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[译文]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1158</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/03/jQuery-hidden-features.png" alt="" title="jQuery-hidden-features" width="100" height="100" class="alignleft size-full wp-image-1162" />
<p>jQuery并不像他表面显示的那样，只有那些额定的方法供我们使用。其他在他库的代码内有着很多很酷很便捷的潜在方法，等待被我们发现。在本文中，我将带领你去领略一些我在jQuery库中发现的那些不怎么常见的方法。</p>
<p>jQuery中的隐藏功能远远不止文章提到的这些，在以后的文章中会再总结一些我自己发现的功能与大家分享。</p>
<p>本文翻译自：<a href="http://net.tutsplus.com/tutorials/javascript-ajax/uncovering-jquerys-hidden-features/" rel="external">Uncovering jQuery’s Hidden Features</a></p>]]></description>
			<content:encoded><![CDATA[<p>jQuery并不像他表面显示的那样，只有那些额定的方法供我们使用。其他在他库的代码内有着很多很酷很便捷的潜在方法，等待被我们发现。在本文中，我将带领你去领略一些我在jQuery库中发现的那些不怎么常见的方法。</p>
<h3>1.理解jQuery方法：</h3>
<p>当你调用jQuery方法时会发生什么呢？看看jQuery的方法体，非常地简单。</p>

<div class="wp_codebox"><table><tr id="p115867"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1158code67"><pre class="javascript" style="font-family:monospace;">jQuery <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>selector<span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// The jQuery object is actually just the init constructor 'enhanced'</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span>selector<span style="color: #339933;">,</span> context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>在表层的代码之下，jQuery方法（通常称之为“包装”方法）将返回一个实例化后的jQuery对象，即&#8217;jQuery.fn.init&#8217;构造函数的一个实例。</p>
<p>理解了这一点非常有用，当我们每次调用jQuery方法时，都会返回一个带有一组属性的完全独立的对象。而jQuery的聪明之处在于返回的这个对象是以数组的方式返回的。该对象中的所有元素（通称”集合“）都是由一个数字索引所指向，就像数组中的下标一样。而且jQuery还返回了一个对象的length属性，就像数组中的长度一样。这种思想给jQuery方法提供了无限的想象空间。比如，我们可以从&#8217;Array.prototype&#8217;中借用一些功能性方法。jQuery中的slice方法就是一个典型的例子：</p>

<div class="wp_codebox"><table><tr id="p115868"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p1158code68"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* ... jQuery.fn.extend({ ... */</span>
slice<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;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">pushStack</span><span style="color: #009900;">&#40;</span>
        Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">slice</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> arguments <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #3366CC;">&quot;slice&quot;</span><span style="color: #339933;">,</span>
        Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">slice</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&lt;</span>wbr<span style="color: #339933;">&gt;</span>arguments<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;,&quot;</span><span style="color: #009900;">&#41;</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: #009966; font-style: italic;">/* ... */</span>
<span style="color: #339933;">&lt;/</span>wbr<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>在该slice方法不管this是否是一个真实的数组，它和其他的元素会和睦地相处，因为有着”length“这么一个属性。
</p>
<p>jQuery中还有一些其他有趣的属性，比如”selector”&#8212;选择器，”context”&#8212;-上下文等。大部分的时候，只需给jQuery方法传递对象参数即可：</p>

<div class="wp_codebox"><table><tr id="p115869"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1158code69"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> jqObject <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jqObject.<span style="color: #660066;">selector</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// =&gt; &quot;a&quot;</span></pre></td></tr></table></div>

<p>一个重要的提示是，jQuery有时会返回一个全新的对象供你使用。比如你试图通过执行一段代码来改变一个集合，如”parent()”方法，但是此时jQuery将不会修改当前的对象，它会返回给你一个全新的对象。</p>

<div class="wp_codebox"><table><tr id="p115870"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1158code70"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> originalObject <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> anotherObject <span style="color: #339933;">=</span> originalObject.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
originalObject <span style="color: #339933;">===</span> anotherObject<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// =&gt; false</span></pre></td></tr></table></div>

</p>
<p>所有试图改变集合的方法都会返回一个新的jQuery对象，你可以通过”.end()”方法或”.prevObject”属性来访问之前的那个对象。</p>
<h3>2.面包、奶油元素的建立：</h3>
<p>jQuery创建DOM的能力，是其核心功能之一。jQuery1.4新版本带来了一个全新的便捷地创建DOM对象的方法，如：</p>

<div class="wp_codebox"><table><tr id="p115871"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p1158code71"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myDiv <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div /&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    id<span style="color: #339933;">:</span> <span style="color: #3366CC;">'my-new-element'</span><span style="color: #339933;">,</span>
    <span style="color: #003366; font-weight: bold;">class</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'foo'</span><span style="color: #339933;">,</span>
    css<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        color<span style="color: #339933;">:</span> <span style="color: #3366CC;">'red'</span><span style="color: #339933;">,</span>
        backgrondColor<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#FFF'</span><span style="color: #339933;">,</span>
        border<span style="color: #339933;">:</span> <span style="color: #3366CC;">'1px solid #CCC'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    click<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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Clicked!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    html<span style="color: #339933;">:</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a /&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        href<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#'</span><span style="color: #339933;">,</span>
        click<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: #006600; font-style: italic;">// do something</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>在1.4版本中，当你创建一个元素对象时，可以再传入第二参数，该第二参宿可以作为该元素对象的属性设置，也可以理解会调用了.attr()方法。当然，jQuery会自行匹配传入的参数们，如&#8217;click&#8217;对应了jQuery库中的.click方法，以及&#8217;css&#8217;、&#8217;html&#8217;分别对应了jQuery库中的.css()、.html()方法，等等&#8230;</p>
<h3>3.序列化表单中的input元素：</h3>
<p>jQuery提供了一个方法可以将1个或多个表单中的所有input元素进行序列化，这在Ajax提交数据时非常有用。其实该方法在jQuery库中已经存在很长的时间了，但一直很少谈及，所以很多的程序员都忽略了它。通过jQuery中的Ajax方法提交整个表单将变得非常简单。</p>

<div class="wp_codebox"><table><tr id="p115872"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1158code72"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myForm <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#my-form'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'submit.php'</span><span style="color: #339933;">,</span> myForm.<span style="color: #660066;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Data has been sent!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>jQuery同样也通过了一个&#8217;serializeArray&#8217;方法，他通常用在多个form表单存在，需要自行收集数据的情况。在jQuery的命名空间下有一个&#8217;param&#8217;辅助方法可以将一个数组对象处理后返回成一个查询字符串。</p>

<div class="wp_codebox"><table><tr id="p115873"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1158code73"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'Joe'</span><span style="color: #339933;">,</span>
    age<span style="color: #339933;">:</span> <span style="color: #CC0000;">44</span><span style="color: #339933;">,</span>
    profession<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Web Developer'</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
jQuery.<span style="color: #660066;">param</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// =&gt; &quot;name=Joe&amp;age=44&amp;profession=&lt;wbr&gt;Web+Developer&quot;</span>
<span style="color: #339933;">&lt;/</span>wbr<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</p>
<h3>4.任何元素都可以动画方式展现：</h3>
<p>jQuery中的&#8217;animate&#8217;方法也许是最灵活的jQuery的方法。它可以用几乎任何东西来制作动画，而不仅仅是CSS属性，或者是DOM元素。通常会这样使用&#8217;动画&#8217;：</p>

<div class="wp_codebox"><table><tr id="p115874"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1158code74"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#box'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    left<span style="color: #339933;">:</span> <span style="color: #CC0000;">300</span><span style="color: #339933;">,</span>
    top<span style="color: #339933;">:</span> <span style="color: #CC0000;">300</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>当您给.animate()方法指定一个属性时（例如&#8217;top&#8217;），jQuery会检查你是否是想通过某个css属性来控制动画风格。首先jQuery会检查css样式中是否存在该top属性，若不存在，则jQuery会自行地给对应元素加上该属性。下面是一个例子：</p>

<div class="wp_codebox"><table><tr id="p115875"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1158code75"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#box'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    top<span style="color: #339933;">:</span> <span style="color: #CC0000;">123</span><span style="color: #339933;">,</span>
    foo<span style="color: #339933;">:</span> <span style="color: #CC0000;">456</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>上面的代码中&#8217;top&#8217;是一个可用的css属性，则jQuery就会改变&#8217;element.style.top&#8217;,但是&#8217;foo&#8217;不是一个可用的css属性，所以jQuery将只更新&#8217;element.foo&#8217;。</p>
<p>我们可以利用这个优点来实现一些有趣的效果。比方说，例如，您要在一个画布上使一个正方形动画起来。首先让我们定义一个简单的构造和一个在每一步都会调用的&#8217;drwa&#8217;的方法：</p>

<div class="wp_codebox"><table><tr id="p115876"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p1158code76"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> Square<span style="color: #009900;">&#40;</span>cnvs<span style="color: #339933;">,</span> width<span style="color: #339933;">,</span> height<span style="color: #339933;">,</span> color<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> width<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> height<span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">color</span> <span style="color: #339933;">=</span> color<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cHeight</span> <span style="color: #339933;">=</span> cnvs.<span style="color: #660066;">height</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cWidth</span> <span style="color: #339933;">=</span> cnvs.<span style="color: #660066;">width</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cntxt</span> <span style="color: #339933;">=</span> cnvs.<span style="color: #660066;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'2d'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
Square.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">draw</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>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cntxt</span>.<span style="color: #660066;">clearRect</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cWidth</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cHeight</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;">cntxt</span>.<span style="color: #660066;">fillStyle</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">color</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cntxt</span>.<span style="color: #660066;">fillRect</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">x</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">y</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">width</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>通过jQuery方法创建一个canvas画布元素（需要html5支持），再实例化一个正方形对象，通过调用.animate()方法在动画的每一步过程中调用.draw()方法，这样就可以轻易地使该正方形动画起来：</p>

<div class="wp_codebox"><table><tr id="p115877"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p1158code77"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Create a &lt;canvas /&gt; element</span>
<span style="color: #003366; font-weight: bold;">var</span> canvas <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;canvas /&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #339933;">&lt;</span>wbr<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
canvas.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">400</span><span style="color: #339933;">;</span>
canvas.<span style="color: #660066;">width</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">600</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Instantiate Square</span>
<span style="color: #003366; font-weight: bold;">var</span> square <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Square<span style="color: #009900;">&#40;</span>canvas<span style="color: #339933;">,</span> <span style="color: #CC0000;">70</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">70</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'rgb(255,0,0)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
jQuery<span style="color: #009900;">&#40;</span>square<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    x<span style="color: #339933;">:</span> <span style="color: #CC0000;">300</span><span style="color: #339933;">,</span>
    y<span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// 'draw' should be called on every step</span>
    <span style="color: #006600; font-style: italic;">// of the animation:</span>
    step<span style="color: #339933;">:</span> jQuery.<span style="color: #660066;">proxy</span><span style="color: #009900;">&#40;</span>square<span style="color: #339933;">,</span> <span style="color: #3366CC;">'draw'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    duration<span style="color: #339933;">:</span> <span style="color: #CC0000;">1000</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>wbr<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</p>
<p>这是一个非常简单的效果，但它清楚地表明了jQuery的无限可能性。你可以通过下面的链接看到具体的效果（需要浏览器支持html5）：<a href="http://jsbin.com/ocida" rel="extrnal">Demo</a></p>
<h3>5.jQuery.ajax方法返回XHR对象：</h3>
<p>jQuery的 Ajax方法是一个多功能的方法，它包含了&#8217;jQuery.ajax&#8217;, &#8216;jQuery.get&#8217;, &#8216;jQuery.post&#8217;等多个方法，这些方法在调用后都会返回一个&#8217;XMLHttpRequest&#8217; 对象，从而来实现请求完成后的后续操作。如：</p>

<div class="wp_codebox"><table><tr id="p115878"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p1158code78"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> curRequest<span style="color: #339933;">;</span>
&nbsp;
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'button.makeRequest'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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>
    curRequest <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'foo.php'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<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;">'Data: '</span> <span style="color: #339933;">+</span> response.<span style="color: #660066;">responseText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'button.cancelRequest'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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>curRequest<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        curRequest.<span style="color: #660066;">abort</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// abort() is a method of XMLHttpRequest</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>上面的代码中当我们点击&#8217;makeRequest&#8217;按钮时，Ajax请求将会被触发。而当我们点击&#8217;cancelRequest&#8217;按钮时，该请求则会被取消。</p>
<p>另一个潜在的用途是同步请求：</p>

<div class="wp_codebox"><table><tr id="p115879"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p1158code79"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myRequest <span style="color: #339933;">=</span> jQuery.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'foo.txt'</span><span style="color: #339933;">,</span>
    async<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>myRequest.<span style="color: #660066;">responseText</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p>请多的资料可以阅读<a href="https://developer.mozilla.org/en/XMLHttpRequest" rel="external">&#8216;XMLHttpRequest&#8217;</a>，也可以阅读Ajax的API文档<a href="http://api.jquery.com/category/ajax/" rel="external">jQuery&#8217;s Ajax utilities</a></p>
<h3>6.自定义队列：</h3>
<p>jQuery的有一个内置的队列机制，一般都是有.animate等动画方法使用的（如：.fadeOut()、.fadeIn()等，实质都是有.animate()方法实现）。这种队列机制可以用一个简单的动画就可以说明：</p>

<div class="wp_codebox"><table><tr id="p115880"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p1158code80"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</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>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>paddingLeft<span style="color: #339933;">:</span><span style="color: #3366CC;">'+=15px'</span><span style="color: #009900;">&#125;</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: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>paddingLeft<span style="color: #339933;">:</span><span style="color: #3366CC;">'-=15px'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>快速地在一个链接标记上鼠标移入、移出，当再次移入时，会导致动画的效果反复执行。不信你可以到这里试试：<a href="http://jsbin.com/aqaku" rel="external">Demo</a></p>
<p>&#8216;queue&#8217;方法和大家熟知的&#8217;each&#8217;方法比较相似，你通过给方法传递一个函数参数，则该函数将被匹配集合中的每个元素所调用：</p>

<div class="wp_codebox"><table><tr id="p115881"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1158code81"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">queue</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>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'all-done'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dequeue</span><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;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>给&#8217;queue&#8217;方法只传入一个函数参数的话会导致该函数被添加到默认的&#8217;fx&#8217;队列中。若刚好该队列会被jQuery中的所有动画对象所调用，那么只有等前面的这些对象都调用后，才会轮到自己。<br />
鉴于该点，在上面的代码中我给对象添加了一个名为&#8217;all-done&#8217;的class，根据协议，这个class只有在当前所有的动画都执行完成后才会添加。在代码中我们也调用了.dequeue()方法。<strongstyle ="color:#f00">这一点很重要，它将使jQuery的继续进行队列。jQuery1.4版本提供了另一个可以继续队列的方法nextItemInQueue()，它可以用来取代调用.dequeue()方法。它的调用只需将第一个参数传递给方法即可：</p>

<div class="wp_codebox"><table><tr id="p115882"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p1158code82"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">queue</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: #339933;">&lt;</span>wbr<span style="color: #339933;">&gt;</span>nextItemInQueue<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Continue queue:</span>
    nextItemInQueue<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;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>wbr<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>当然两个方法也不完全相同，nextItemInQueue()可以在方法体内部的任何地方都可以调用，即使在一团糟的匿名函数内（典型情况是&#8217;this&#8217;对象被破坏）。当然在1.4版本前，你可以尽可能地保存一个对&#8217;this&#8217;对象的引用，但这样使用起来有点累。</strongstyle></p>
<p>要想向自定义队列中添加方法，只需将你自定义的队列名称作为第一参数，而将方法体作为第二参数传入即可：</p>

<div class="wp_codebox"><table><tr id="p115883"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1158code83"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">queue</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'customQueueName'</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>
    <span style="color: #006600; font-style: italic;">// Do stuff</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">dequeue</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'customQueueName'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>需要认识的一点，为了不将该队列添加到默认的&#8217;fx&#8217;队列中，我们需要将自定义的队列名传入.dequeue()方法中，这样在队列结束后，可以保证jQuery队列可以继续执行下去。</p>
<p>更多的资料可以阅读<a href="http://api.jquery.com/queue" rel="external" class="p_5">&#8216;queue&#8217;</a>,<a href="http://api.jquery.com/dequeue/" rel="external" class="p_5">&#8216;dequeue&#8217;</a>,<a href="http://api.jquery.com/jQuery.queue/" rel="external" class="p_5">&#8216;jQuery.queue&#8217;</a></p>
<h3>7.事件命名空间：</h3>
<p>jQuery提供了一个命名时间名称的方法，这在编写插件或第三方组件时非常有用。当需要时，您的插件用户可以通过取消绑定这些你注册事件名称即可。<br />
<br />向命名空间中添加注册一个事件处理名称，只需在事件名称后添加自定义的后缀名（如：.fooPlugin):</p>

<div class="wp_codebox"><table><tr id="p115884"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p1158code84"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">foo</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>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click.fooPlugin'</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>
        <span style="color: #006600; font-style: italic;">// do stuff</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseover.fooPlugin'</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>
        <span style="color: #006600; font-style: italic;">// do stuff</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Use the plugin:</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">foo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Destroy its event handlers:</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.fooPlugin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>取消绑定是只需调用.unbind()方法，并传入自定义事件名称即可实现。</p>
<h3>总结：</h3>
<p>jQuery中的隐藏功能远远不止这些，在以后的文章中会再总结一些我自己发现的功能与大家分享。</p>
<p>本文翻译自：<a href="http://net.tutsplus.com/tutorials/javascript-ajax/uncovering-jquerys-hidden-features/" rel="external">Uncovering jQuery’s Hidden Features</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li><li>2010年01月20日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a> (6)</li><li>2010年03月8日 -- <a href="http://www.ihiro.org/css3-basic" title="CSS:CSS3基础（附图）">CSS:CSS3基础（附图）</a> (12)</li><li>2009年12月18日 -- <a href="http://www.ihiro.org/10-javascript-tips" title="Javascript:10个Javscript编程的技巧">Javascript:10个Javscript编程的技巧</a> (4)</li><li>2009年12月16日 -- <a href="http://www.ihiro.org/jquery-once-through-the-event-delegate-to-bind-a-variety-of-time-in-order-to-reduce-the-event-of-redundancy" title="jQuery:通过事件委派一次绑定多种事件，以减少事件冗余">jQuery:通过事件委派一次绑定多种事件，以减少事件冗余</a> (7)</li><li>2009年12月1日 -- <a href="http://www.ihiro.org/how-to-custom-alias-in-plugins-and-page-code" title="jQuery:如何在页面和插件代码中自定义别名">jQuery:如何在页面和插件代码中自定义别名</a> (5)</li><li>2009年11月30日 -- <a href="http://www.ihiro.org/coding-clean-and-rich-semantic-html" title="HTML:编写干净的且富有语义的html代码">HTML:编写干净的且富有语义的html代码</a> (13)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年08月6日 -- <a href="http://www.ihiro.org/drop-down-menu" title="jQuery:两个样式下拉菜单(click hover)">jQuery:两个样式下拉菜单(click hover)</a> (8)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/uncovering-jquerys-hidden-features/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>CSS:CSS3基础（附图）</title>
		<link>http://www.ihiro.org/css3-basic</link>
		<comments>http://www.ihiro.org/css3-basic#comments</comments>
		<pubDate>Mon, 08 Mar 2010 02:41:14 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[CSS、XHTML]]></category>
		<category><![CDATA[前端工程译文]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[译文]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/css-css3-based-with-photos</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/03/css3-basics.gif" alt="" title="css3-basics" width="100" height="100" class="alignleft size-full wp-image-1138" />
<p>今日在<a href="http://www.webdesignerwall.com/" rel="external">Web Designer Wall</a>博客上看到这篇介绍css3基础的博文，文章其实很普通，关键喜欢他配上了截图，看起来就更加明了。便花了点时间整理后发表出来与大家分享一下！</p>
<p>文中主要介绍了四个css3高级属性，也是最最常用的四个css3属性。</p>
<p>最后，css3高级属性远远不值文中的这些，文中讲到的是一些基础的，也是使用最多的，为了给用户带去更多的美好体验，努力学透css吧！</p>
<p>本文翻译自：<a href="http://www.webdesignerwall.com/tutorials/the-basics-of-css3/" rel="external">Web Designer Wall -- The Basics of CSS3</a></p>]]></description>
			<content:encoded><![CDATA[<p>今日在<a href="http://www.webdesignerwall.com/" rel="external">Web Designer Wall</a>博客上看到这篇介绍css3基础的博文，文章其实很普通，关键喜欢他配上了截图，看起来就更加明了。便花了点时间整理后发表出来与大家分享一下！</p>
<p>文中主要介绍了四个css3高级属性，也是最最常用的四个css3属性。</p>
<h3>1.RGBA</h3>
<p>RBGA是用于css的background属性，前三个参数是RBG颜色值，最后一个参数是透明度设置。<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/03/css3-rgba.gif" alt="" title="css3-rgba" width="470" height="276" class="aligncenter size-full wp-image-1143" />RGBA也可以使用在css中与颜色相关的所有属性中，如color,border-color,background-color,shadow-color等。<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/03/css3-rgba2.gif" alt="" title="css3-rgba2" width="470" height="303" class="aligncenter size-full wp-image-1144" /></p>
<h3>2.Text Shadow</h3>
<p>text-shadow的设置值是由x-offset, y-offset, blur, color四个参数组成。<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/03/css3-text-shadow.gif" alt="" title="css3-text-shadow" width="470" height="276" class="aligncenter size-full wp-image-1145" />若给x-offset设置一个负值，则阴影偏向左边；若个y-offset设置一个负值，则阴影偏向顶部；当然你也可以使用RGBA来设置第四个参数color。<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/03/css3-text-shadow-example2.gif" alt="" title="css3-text-shadow-example2" width="470" height="114" class="aligncenter size-full wp-image-1146" />你也可以给text-shadow设置一系列的值（用逗号隔开）。下面的图片展示了两个值来设置一个单词的印刷效果（1px向上，1px向下）：<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/03/css3-text-shadow-example3.gif" alt="" title="css3-text-shadow-example3" width="470" height="114" class="aligncenter size-full wp-image-1147" /></p>
<h3>3.Border Radius</h3>
<p>对border radius的记忆方法就和padding、margin一样(如： border-radius: 20px)。为了达到多浏览器兼容，需要在该属性前加上“-moz-“用于火狐浏览器、加上”-webkit-“用于谷歌和苹果浏览器。（IE浏览器不支持此CSS3高级属性）<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/03/css3-border-radius.gif" alt="" title="css3-border-radius" width="470" height="340" class="aligncenter size-full wp-image-1139" />你也可以分别设置四个角的圆角直径，火狐浏览器与苹果（谷歌)浏览器的设置属性有所差别，看图：<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/03/css3-border-radius-corners.gif" alt="" title="css3-border-radius-corners" width="470" height="460" class="aligncenter size-full wp-image-1140" /></p>
<h3>4.Box Shadow</h3>
<p>box shadow属性设置值的构成与text-shadow是一样的，都是有四个属性：x-offset, y-offset, blur, color组成。<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/03/css3-box-shadow.gif" alt="" title="css3-box-shadow" width="470" height="353" class="aligncenter size-full wp-image-1141" />当然，box-shadow也可以用一系列的值来设置属性，如：</p>

<div class="wp_codebox"><table><tr id="p114885"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1148code85"><pre class="css" style="font-family:monospace;">-moz-box-shadow<span style="color: #00AA00;">:</span>
		<span style="color: #933;">-2px</span> <span style="color: #933;">-2px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">,</span>
		<span style="color: #933;">2px</span> <span style="color: #933;">2px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc00cc;">#bb9595</span><span style="color: #00AA00;">,</span>
		<span style="color: #933;">2px</span> <span style="color: #933;">4px</span> <span style="color: #933;">15px</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">,</span> .3<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span></pre></td></tr></table></div>

<p>效果如下图：<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/03/css3-box-shadow2.gif" alt="" title="css3-box-shadow2" width="470" height="278" class="aligncenter size-full wp-image-1142" /></p>
<p>最后，css3高级属性远远不值文中的这些，文中讲到的是一些基础的，也是使用最多的，为了给用户带去更多的美好体验，努力学透css吧！</p>
<p>本文翻译自:<a href="http://www.webdesignerwall.com/tutorials/the-basics-of-css3/" rel="external">Web Designer Wall &#8212; The Basics of CSS3</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年03月2日 -- <a href="http://www.ihiro.org/css-specific-for-internet-explorer" title="CSS:区分IE版本的三个方法">CSS:区分IE版本的三个方法</a> (27)</li><li>2010年11月25日 -- <a href="http://www.ihiro.org/css-position-hack" title="CSS:position属性定位总结">CSS:position属性定位总结</a> (28)</li><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li><li>2010年01月20日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a> (6)</li><li>2009年12月18日 -- <a href="http://www.ihiro.org/10-javascript-tips" title="Javascript:10个Javscript编程的技巧">Javascript:10个Javscript编程的技巧</a> (4)</li><li>2009年11月30日 -- <a href="http://www.ihiro.org/coding-clean-and-rich-semantic-html" title="HTML:编写干净的且富有语义的html代码">HTML:编写干净的且富有语义的html代码</a> (13)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/css3-basic/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>jQuery:丰富效果的Flash图片播放（JS重写版）</title>
		<link>http://www.ihiro.org/a-rich-picture-effect-flash</link>
		<comments>http://www.ihiro.org/a-rich-picture-effect-flash#comments</comments>
		<pubDate>Fri, 26 Feb 2010 07:17:13 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[插件开发]]></category>
		<category><![CDATA[案例分享]]></category>
		<category><![CDATA[Cases]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1129</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/02/flashImgPlay-logo.jpg" alt="" title="flashImgPlay-logo" width="100" height="100" class="alignleft size-full wp-image-1132" />
<p>大家看到这个图片播放效果的演示后一定觉得很熟悉吧，因为该效果使用的地方是在太多了。但凡比较大型的网站上都有图片播放的效果，有的是单一的图片切换、有的是图片渐入渐出、还有的就是左滑右滑。而我演示的这个版本则是播放效果比较丰富的，所以也是使用比较广泛的。</p>
<p>在以前的公司一个人做网站时我就曾将它作为公司网站首页的图片播放效果，那个时候我的Js不好，纯粹是拿了代码后套进内容，然后放到网上去就万事OK了。现在不一样了，JS编程熟悉了，jQuery库更是熟悉，便觉得原始的代码怎么看都不爽，昨天终于将该效果的JS代码重写了一下，贴出来与大家分享！</p>]]></description>
			<content:encoded><![CDATA[<p>大家看到这个图片播放效果的演示后一定觉得很熟悉吧，因为该效果使用的地方是在太多了。但凡比较大型的网站上都有图片播放的效果，有的是单一的图片切换、有的是图片渐入渐出、还有的就是左滑右滑。而我演示的这个版本则是播放效果比较丰富的，所以也是使用比较广泛的。</p>
<p>在以前的公司一个人做网站时我就曾将它作为公司网站首页的图片播放效果，那个时候我的Js不好，纯粹是拿了代码后套进内容，然后放到网上去就万事OK了。现在不一样了，JS编程熟悉了，jQuery库更是熟悉，便觉得原始的代码怎么看都不爽，昨天终于将该效果的JS代码重写了一下，贴出来与大家分享！</p>
<p>先来看看重写后的播放效果吧！</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/flashImgPlay/flashImgPlay.rar" class="download">download</a> <a href="http://www.ihiro.org/cases/flashImgPlay/" rel="external" class="demo">demo</a></p>
<h3>一、下载后的初始Html代码和JS代码：</h3>
<p>
Html代码(在需要显示图片播放的代码处添加)：</p>

<div class="wp_codebox"><table><tr id="p112986"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1129code86"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;flashImgPlay.js&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>

<p>flashImgPlay.js中的Javascript代码:</p>

<div class="wp_codebox"><table><tr id="p112987"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code" id="p1129code87"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> pic_width<span style="color: #339933;">=</span><span style="color: #CC0000;">480</span><span style="color: #339933;">;</span> 
<span style="color: #003366; font-weight: bold;">var</span> pic_height<span style="color: #339933;">=</span><span style="color: #CC0000;">166</span><span style="color: #339933;">;</span> 
<span style="color: #003366; font-weight: bold;">var</span> button_pos<span style="color: #339933;">=</span><span style="color: #CC0000;">3</span><span style="color: #339933;">;</span> 
<span style="color: #003366; font-weight: bold;">var</span> stop_time<span style="color: #339933;">=</span><span style="color: #CC0000;">3000</span><span style="color: #339933;">;</span> 
<span style="color: #003366; font-weight: bold;">var</span> show_text<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> 
<span style="color: #003366; font-weight: bold;">var</span> txtcolor<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;000000&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #003366; font-weight: bold;">var</span> bgcolor<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;DDDDDD&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #003366; font-weight: bold;">var</span> imag<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> link<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> text<span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
imag<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;images/pics/news09-col-manual.jpg&quot;</span><span style="color: #339933;">;</span>
link<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;news/coll-manual.php&quot;</span><span style="color: #339933;">;</span>
imag<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;images/pics/news02.jpg&quot;</span><span style="color: #339933;">;</span>
link<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;news/mid_school.php&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> swf_height<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>show_text<span style="color: #339933;">==</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>pic_height<span style="color: #339933;">+</span><span style="color: #CC0000;">20</span><span style="color: #339933;">:</span>pic_height<span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> pics<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span> links<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #339933;">,</span> texts<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&quot;</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;">1</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>imag .<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	pics<span style="color: #339933;">=</span>pics<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;|&quot;</span><span style="color: #339933;">+</span>imag<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	links<span style="color: #339933;">=</span>links<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;|&quot;</span><span style="color: #339933;">+</span>link<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	texts<span style="color: #339933;">=</span>texts<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;|&quot;</span><span style="color: #339933;">+</span>text<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>
pics<span style="color: #339933;">=</span>pics.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
links<span style="color: #339933;">=</span>links.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
texts<span style="color: #339933;">=</span>texts.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;object classid=&quot;clsid:d27cdb6e-ae6d-11cf-96b8-444553540000&quot; codebase=&quot;http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cabversion=6,0,0,0&quot; width=&quot;'</span><span style="color: #339933;">+</span> pic_width <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; height=&quot;'</span><span style="color: #339933;">+</span> swf_height <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;param name=&quot;movie&quot; value=&quot;flash/focus.swf&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;/param&gt;&lt;param name=&quot;quality&quot; value=&quot;high&quot;&gt;&lt;/param&gt;&lt;param name=&quot;wmode&quot; value=&quot;opaque&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;/param&gt;&lt;param name=&quot;FlashVars&quot; value=&quot;pics='</span><span style="color: #339933;">+</span>pics<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;links='</span><span style="color: #339933;">+</span>links<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;texts='</span><span style="color: #339933;">+</span>texts<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;pic_width='</span><span style="color: #339933;">+</span>pic_width<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;pic_height='</span><span style="color: #339933;">+</span>pic_height<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;show_text='</span><span style="color: #339933;">+</span>show_text<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;txtcolor='</span><span style="color: #339933;">+</span>txtcolor<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;bgcolor='</span><span style="color: #339933;">+</span>bgcolor<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;button_pos='</span><span style="color: #339933;">+</span>button_pos<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;stop_time='</span><span style="color: #339933;">+</span>stop_time<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;embed src=&quot;flash/focus.swf&quot; FlashVars=&quot;pics='</span><span style="color: #339933;">+</span>pics<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;links='</span><span style="color: #339933;">+</span>links<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;texts='</span><span style="color: #339933;">+</span>texts<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;pic_width='</span><span style="color: #339933;">+</span>pic_width<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;pic_height='</span><span style="color: #339933;">+</span>pic_height<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;show_text='</span><span style="color: #339933;">+</span>show_text<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;txtcolor='</span><span style="color: #339933;">+</span>txtcolor<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;bgcolor='</span><span style="color: #339933;">+</span>bgcolor<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;button_pos='</span><span style="color: #339933;">+</span>button_pos<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;stop_time='</span><span style="color: #339933;">+</span>stop_time<span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; quality=&quot;high&quot; width=&quot;'</span><span style="color: #339933;">+</span> pic_width <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; height=&quot;'</span><span style="color: #339933;">+</span> swf_height <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; allowScriptAccess=&quot;sameDomain&quot; type=&quot;application/x-shockwave-flash&quot; pluginspage=&quot;http://www.macromedia.com/go/getflashplayer&quot; /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>param<span style="color: #339933;">&gt;&lt;/</span>imag<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</p>
<h3>二、重写后的Html代码、Css代码以及JS代码：</h3>
<p>
Html代码(在需要显示图片播放的代码处添加)：</p>

<div class="wp_codebox"><table><tr id="p112988"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1129code88"><pre class="html" style="font-family:monospace;">&lt;div class=&quot;flash&quot;&gt;
    &lt;ul&gt;
        &lt;li class=&quot;first&quot;&gt;&lt;a href=&quot;#&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;1.jpg&quot; alt=&quot;banner1&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;2.jpg&quot; alt=&quot;banner2&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;3.jpg&quot; alt=&quot;banner3&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot; target=&quot;_blank&quot;&gt;&lt;img src=&quot;4.jpg&quot; alt=&quot;banner4&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p>需要用到的Css代码：</p>

<div class="wp_codebox"><table><tr id="p112989"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p1129code89"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.flash</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">500px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.flash</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.flash</span> li<span style="color: #6666ff;">.first</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>flashImgPlay.js中的Javascript代码（插件方式）:</p>

<div class="wp_codebox"><table><tr id="p112990"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
</pre></td><td class="code" id="p1129code90"><pre class="javascript" style="font-family:monospace;"><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: #660066;">fn</span>.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		flashImgPlay <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<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;">this</span>.<span style="color: #660066;">each</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> defaults <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
					width <span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img:first'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
					height <span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img:first'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
					btn_pos <span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span>
					stop_time <span style="color: #339933;">:</span> <span style="color: #CC0000;">3000</span><span style="color: #339933;">,</span>
					show_text <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
					txtcolor <span style="color: #339933;">:</span> <span style="color: #3366CC;">'000000'</span><span style="color: #339933;">,</span>
					bgcolor <span style="color: #339933;">:</span> <span style="color: #3366CC;">'dddddd'</span><span style="color: #339933;">,</span>
					flash_src <span style="color: #339933;">:</span> <span style="color: #3366CC;">'focus.swf'</span>
				<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #003366; font-weight: bold;">var</span> images <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
					imgs <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
					links <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
					texts <span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</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>
					images.<span style="color: #660066;">imgs</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					images.<span style="color: #660066;">links</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</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: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					images.<span style="color: #660066;">texts</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'alt'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #003366; font-weight: bold;">var</span> swf_height <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>defaults.<span style="color: #660066;">show_text</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #009900;">&#40;</span>defaults.<span style="color: #660066;">height</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> defaults.<span style="color: #660066;">height</span><span style="color: #339933;">,</span>
					pics <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">,</span> links <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">,</span> texts <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
				<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> length <span style="color: #339933;">=</span> images.<span style="color: #660066;">imgs</span>.<span style="color: #660066;">length</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>
					pics <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'|'</span> <span style="color: #339933;">+</span> images.<span style="color: #660066;">imgs</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
					links <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'|'</span> <span style="color: #339933;">+</span> images.<span style="color: #660066;">links</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
					texts <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'|'</span> <span style="color: #339933;">+</span> images.<span style="color: #660066;">texts</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
				pics <span style="color: #339933;">=</span> pics.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				links <span style="color: #339933;">=</span> links.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
				texts <span style="color: #339933;">=</span> texts.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>
					<span style="color: #3366CC;">'&lt;object classid=&quot;clsid:d27cdb6e-ae6d-11cf-96b8-444553540000&quot; codebase=&quot;http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cabversion=6,0,0,0&quot; width=&quot;'</span><span style="color: #339933;">+</span> defaults.<span style="color: #660066;">width</span> <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; height=&quot;'</span><span style="color: #339933;">+</span> swf_height <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span>
						<span style="color: #3366CC;">'&lt;param name=&quot;movie&quot; value=&quot;'</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">flash_src</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span>
						<span style="color: #3366CC;">'&lt;/param&gt;&lt;param name=&quot;quality&quot; value=&quot;high&quot;&gt;&lt;/param&gt;&lt;param name=&quot;wmode&quot; value=&quot;opaque&quot;&gt;'</span> <span style="color: #339933;">+</span>
						<span style="color: #3366CC;">'&lt;/param&gt;&lt;param name=&quot;FlashVars&quot; value=&quot;pics='</span><span style="color: #339933;">+</span>pics<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;links='</span><span style="color: #339933;">+</span>links<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;texts='</span><span style="color: #339933;">+</span>texts<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;pic_width='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">width</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;pic_height='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">height</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;show_text='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">show_text</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;txtcolor='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">txtcolor</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;bgcolor='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">bgcolor</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;button_pos='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">btn_pos</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;stop_time='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">stop_time</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;&gt;'</span> <span style="color: #339933;">+</span>
						<span style="color: #3366CC;">'&lt;embed src=&quot;'</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">flash_src</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; FlashVars=&quot;pics='</span><span style="color: #339933;">+</span>pics<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;links='</span><span style="color: #339933;">+</span>links<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;texts='</span><span style="color: #339933;">+</span>texts<span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;pic_width='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">width</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;pic_height='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">height</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;show_text='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">show_text</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;txtcolor='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">txtcolor</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;bgcolor='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">bgcolor</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;button_pos='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">btn_pos</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&amp;stop_time='</span><span style="color: #339933;">+</span>defaults.<span style="color: #660066;">stop_time</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; quality=&quot;high&quot; width=&quot;'</span><span style="color: #339933;">+</span> defaults.<span style="color: #660066;">width</span> <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; height=&quot;'</span><span style="color: #339933;">+</span> swf_height <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; allowScriptAccess=&quot;sameDomain&quot; type=&quot;application/x-shockwave-flash&quot; pluginspage=&quot;http://www.macromedia.com/go/getflashplayer&quot; /&gt;'</span> <span style="color: #339933;">+</span>
					<span style="color: #3366CC;">''</span>
				<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>param<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>调用方法：</p>

<div class="wp_codebox"><table><tr id="p112991"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1129code91"><pre class="javascript" style="font-family:monospace;">jQuery<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: #009900;">&#40;</span><span style="color: #3366CC;">'.flash'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">flashImgPlay</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">//$('.flash').flashImgPlay({stop_time:200, show_text:1}); 自行设置播放间隔、是否显示图片标题  </span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>三、重写前后的比较说明：</h3>
<p>原始代码使用需要在Html代码内嵌入js文件，若一个页面中需要多个图片播放的话（大型网站上常有），就需要创建多个JS文件，并在一个页面中多次引入JS文件嵌套到Html代码内。这严重违背了三层分离的原则。重写后的插件版，只需在文档底部引入一次JS文件，通过方法调用就可以实现一个页面中多个图片播放效果。新代码是自识别图片的大小，从而实现自适应效果。</p>
<p style="color:#f00">不过貌似该效果使用到的foucs.swf的as代码中没有支持.gif格式的图片（这也是我多花了半个小时来调试），又因我暂时还不太会AS编程，所以没对focus.swf进行修改。所以大家使用时图片需采用.jpg格式。另外貌似若设置show_text:1的话，就是显示图片的标题，默认的第一个是现实原作者的版权链接。这些只是对该foucs.swf的bug的说明！</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年02月24日 -- <a href="http://www.ihiro.org/scroll-images" title="Javascript:图片无限循环滚动">Javascript:图片无限循环滚动</a> (27)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年02月24日 -- <a href="http://www.ihiro.org/javascript-news-flash-header-tips" title="Javascript:新消息闪烁标题提示代码分享">Javascript:新消息闪烁标题提示代码分享</a> (7)</li><li>2009年08月28日 -- <a href="http://www.ihiro.org/jquery-hot-pictures-showing-effects-of-rotation" title="jQuery:热点图片轮换展示效果">jQuery:热点图片轮换展示效果</a> (14)</li><li>2009年07月14日 -- <a href="http://www.ihiro.org/keyboard-simulation-with-css-and-jquery" title="jQuery:使用css+jQuery模拟键盘">jQuery:使用css+jQuery模拟键盘</a> (10)</li><li>2009年07月10日 -- <a href="http://www.ihiro.org/the-effection-of-books-show" title="jQuery:书籍展示效果">jQuery:书籍展示效果</a> (6)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/the-effection-of-tab-like-msn" title="jQuery:仿MSN网站的tab效果">jQuery:仿MSN网站的tab效果</a> (30)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/a-simple-6-lines-of-code-to-achieve-the-tab-effecttion" title="jQuery：简单6行代码实现tab效果">jQuery：简单6行代码实现tab效果</a> (10)</li><li>2009年06月30日 -- <a href="http://www.ihiro.org/the-effection-of-thunder-home-page" title="jQuery：仿迅雷首页热片滑动效果">jQuery：仿迅雷首页热片滑动效果</a> (6)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/a-rich-picture-effect-flash/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Javascript:新消息闪烁标题提示代码分享</title>
		<link>http://www.ihiro.org/javascript-news-flash-header-tips</link>
		<comments>http://www.ihiro.org/javascript-news-flash-header-tips#comments</comments>
		<pubDate>Wed, 24 Feb 2010 07:04:25 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[案例分享]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/javascript-news-flash-header-tips</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/02/blinkTitle-logo.png" alt="" title="blinkTitle-logo" width="100" height="100" class="alignleft size-full wp-image-1124" />
<p>本文纯粹是贴出一些比较实用的代码出来供大家学习和使用，也算是个人博客对这些实用代码的记录和收集吧！有用到的可以参考，没用到的直接可以飘过！</p>
<p>特意将这些代码写成jQuery插件的格式，这样方便大家使用的时候调用。我在平时的开发和自我学习过程中也积累了不少有用的代码，不知道怎么概括性地发布出来，所以就已文章的形式陆续贴出来与大家分享。</p>

<p>以单篇文章发布的插件代码都是一些简单的代码，若是一些复杂的代码或插件我会归纳到插件专区里去，这样大家下载起来也方便！</p>]]></description>
			<content:encoded><![CDATA[<p>本文纯粹是贴出一些比较实用的代码出来供大家学习和使用，也算是个人博客对这些实用代码的记录和收集吧！有用到的可以参考，没用到的直接可以飘过！</p>
<p>特意将这些代码写成jQuery插件的格式，这样方便大家使用的时候调用。我在平时的开发和自我学习过程中也积累了不少有用的代码，不知道怎么概括性地发布出来，所以就已文章的形式陆续贴出来与大家分享。</p>
<p>以单篇文章发布的插件代码都是一些简单的代码，若是一些复杂的代码或插件我会归纳到插件专区里去，这样大家下载起来也方便！</p>
<h3>一、插件代码</h3>
<p>
<div class="wp_codebox"><table><tr id="p112592"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code" id="p1125code92"><pre class="javascript" style="font-family:monospace;"><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>
&nbsp;
	$.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">/**
		 * 调用方法： var timerArr = $.blinkTitle.show();
		 *			$.blinkTitle.clear(timerArr);
		 */</span>
		blinkTitle <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
			show <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: #006600; font-style: italic;">//有新消息时在title处闪烁提示</span>
				<span style="color: #003366; font-weight: bold;">var</span> step<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> _title <span style="color: #339933;">=</span> document.<span style="color: #660066;">title</span><span style="color: #339933;">;</span>
&nbsp;
				<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>
					step<span style="color: #339933;">++;</span>
					<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>step<span style="color: #339933;">==</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>step<span style="color: #339933;">=</span><span style="color: #CC0000;">1</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>step<span style="color: #339933;">==</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>document.<span style="color: #660066;">title</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'【　　　】'</span><span style="color: #339933;">+</span>_title<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>step<span style="color: #339933;">==</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>document.<span style="color: #660066;">title</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'【新消息】'</span><span style="color: #339933;">+</span>_title<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#91;</span>timer<span style="color: #339933;">,</span> _title<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">/**
			 * @param timerArr[0], timer标记
			 * @param timerArr[1], 初始的title文本内容
			 */</span>
			clear <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>timerArr<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	<span style="color: #006600; font-style: italic;">//去除闪烁提示，恢复初始title文本</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>timerArr<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					clearInterval<span style="color: #009900;">&#40;</span>timerArr<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
					document.<span style="color: #660066;">title</span> <span style="color: #339933;">=</span> timerArr<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</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: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>注意其中调用方法中的timerArr变量，若你在前面调用代码显示了效果，在页面的后面代码中需要清楚该闪烁效果的话，需要注意timerArr变量的作用域。若只是出现效果而无需清楚，则可以直接调用$.hiro.blinkNews.show()
</p>
<h3>二、调用方法</h3>
<p>
<div class="wp_codebox"><table><tr id="p112593"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p1125code93"><pre class="javascript" style="font-family:monospace;">jQuery<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> timerArr <span style="color: #339933;">=</span> $.<span style="color: #660066;">blinkTitle</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	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>		<span style="color: #006600; font-style: italic;">//此处是过一定时间后自动消失</span>
		$.<span style="color: #660066;">blinkTitle</span>.<span style="color: #660066;">clear</span><span style="color: #009900;">&#40;</span>timerArr<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: #CC0000;">10000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//若人为操作消失，只需如此调用：	$.blinkTitle.clear(timerArr);</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/blinkTitle/blinkTitle.rar" class="download">download</a><a href="http://www.ihiro.org/cases/blinkTitle/" rel="external" class="demo">demo</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年10月21日 -- <a href="http://www.ihiro.org/jquery-plugin-recommended-maphighlight" title="jQuery:热区高亮maphighlight插件推荐">jQuery:热区高亮maphighlight插件推荐</a> (23)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2010年06月30日 -- <a href="http://www.ihiro.org/firebug-console-panel-function" title="Firebug:Javascript测试利器，Console面板函数详解">Firebug:Javascript测试利器，Console面板函数详解</a> (4)</li><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li><li>2009年11月2日 -- <a href="http://www.ihiro.org/my-first-plugin-scrolltop" title="插件:我的第一个插件&#8211;简约的scrollTop滑动插件">插件:我的第一个插件&#8211;简约的scrollTop滑动插件</a> (23)</li><li>2009年08月21日 -- <a href="http://www.ihiro.org/jquery-scrolltop-plugins" title="jQuery:Scrolltop滑动插件推荐（修正注释版）">jQuery:Scrolltop滑动插件推荐（修正注释版）</a> (25)</li><li>2009年06月18日 -- <a href="http://www.ihiro.org/jquery-plugins-for-dw4" title="jQuery plugins for DW4">jQuery plugins for DW4</a> (2)</li><li>2011年11月25日 -- <a href="http://www.ihiro.org/firebug-extension-firequery" title="插件：Firebug扩展插件FireQuery">插件：Firebug扩展插件FireQuery</a> (2)</li><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/javascript-news-flash-header-tips/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>jQuery:1.4新版本中你应该知道的15个新特性(二)</title>
		<link>http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2</link>
		<comments>http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2#comments</comments>
		<pubDate>Fri, 22 Jan 2010 05:04:47 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[前端工程译文]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[译文]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1054</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/01/jquery-1.4-logo-2.gif" alt="" title="jquery-1.4-logo-2" width="100" height="100" class="alignleft size-full wp-image-1044" />
<p>继续发布jQuery1.4版本剩余的新特性：第9点至第15点。</p>
<h3>九、去除标签元素的父标签；</h3>
<h3>十、不用删除数据，即可删除掉DOM中的标签元素；</h3>
<h3>十一、对.index()方法进行了扩展；</h3>
<h3>十二、DOM控制方法支持回调函数...</h3>]]></description>
			<content:encoded><![CDATA[<p>继续发布jQuery1.4版本剩余的新特性：第9点至第15点。</p>
<h3>九、去除标签元素的父标签：</h3>
<p>在之前的版本中已经有了.wrap()方法来个标签添加新的父标签，而在1.4新版本中又添加了相对的.unwrap()方法来去除标签的父标签。实例Html代码如下：</p>

<div class="wp_codebox"><table><tr id="p105494"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1054code94"><pre class="html" style="font-family:monospace;">&lt;div&gt;
    &lt;p&gt;Foo&lt;/p&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p><small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p105495"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1054code95"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'p'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unwrap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>执行后的话题Html代码如下:</p>

<div class="wp_codebox"><table><tr id="p105496"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1054code96"><pre class="html" style="font-family:monospace;">&lt;p&gt;Foo&lt;/p&gt;</pre></td></tr></table></div>

</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/unwrap/" class="p_5" rel="external">.unwrap()</a>方法的资料&#8230;</p>
<h3>十、不用删除数据，即可删除掉DOM中的标签元素：</h3>
<p>新版本中的.detach()方法允许你删除DOM中的任何标签元素，就像.remove()方法一样。但它与.remove()方法的不同之处是：.remove()是将标签直接删除，而.detach()方法则是将标签暂时移除，并通过方法内部调用.data()方法将标签缓存后赋予变量，再后面的代码中若还需要找回该标签，变量则会自动读取缓存的数据；另外若被.detach()方法移除的标签在移除前绑定了事件机制的话，在后面恢复后，该事件机制依然存在，无需再次绑定。<br />
<small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p105497"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p1054code97"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> foo <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#foo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Bind an important event handler</span>
foo.<span style="color: #660066;">click</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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Foo!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
foo.<span style="color: #660066;">detach</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Remove it from the DOM</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// … do stuff</span>
&nbsp;
foo.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Add it back to the DOM</span>
&nbsp;
foo.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// alerts &quot;Foo!&quot;</span></pre></td></tr></table></div>

</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/detach" class="p_5" rel="external">.detach()</a>方法的资料&#8230;</p>
<h3>十一、对.index()方法进行了扩展：</h3>
<p>1.4新版本中新增了两个.index()的调用方法。而之前，我们将一个标签元素作为.index()方法的参数，并希望执行后返回一个标识当前集合中匹配元素序列号的数字结果。<br />
<br /><small class="red">若有一段XHtml代码如下：</small></p>

<div class="wp_codebox"><table><tr id="p105498"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1054code98"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Apple<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Banana<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Grape<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Strawberry<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Pear<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Peach<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>点击li标签获得该li标签的序号<br />
<br /><small class="red">jQuery1.32版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p105499"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1054code99"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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;">alert</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">index</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;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1054100"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p1054code100"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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;">alert</span><span style="color: #009900;">&#40;</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: #660066;">index</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//或者</span>
&nbsp;
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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;">alert</span><span style="color: #009900;">&#40;</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: #660066;">index</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>				   
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/index" class="p_5" rel="external">.index()</a>方法的资料&#8230;</p>
<h3>十二、DOM控制方法支持回调函数：</h3>
<p>在1.4版本中绝大部分的DOM控制方法只支持回调函数作为唯一的参数，除了极个别的（比如：.attr()、.css()）方法中可以作为第二参数。这些回调函数将被匹配集合中所有元素所执行，<br />
以确定哪些应作为该方法的实际值。<br />
<br />下面的这些DOM控制方法都支持回调函数：</p>
<ul class="external" style="padding-left:30px; list-style:inside disc;">
<li><a href="http://api.jquery.com/after">after</a></li>
<li><a href="http://api.jquery.com/before">before</a></li>
<li><a href="http://api.jquery.com/append">append</a></li>
<li><a href="http://api.jquery.com/prepend">prepend</a></li>
<li><a href="http://api.jquery.com/addClass">addClass</a></li>
<li><a href="http://api.jquery.com/toggleClass">toggleClass</a></li>
<li><a href="http://api.jquery.com/removeClass">removeClass</a></li>
<li><a href="http://api.jquery.com/wrap">wrap</a></li>
<li><a href="http://api.jquery.com/wrapAll">wrapAll</a></li>
<li><a href="http://api.jquery.com/wrapInner">wrapInner</a></li>
<li><a href="http://api.jquery.com/val">val</a></li>
<li><a href="http://api.jquery.com/text">text</a></li>
<li><a href="http://api.jquery.com/replaceWith">replaceWith</a></li>
<li><a href="http://api.jquery.com/css">css</a></li>
<li><a href="http://api.jquery.com/attr">attr</a></li>
<li><a href="http://api.jquery.com/html">html</a></li>
</ul>
<p>在回调方法中，若你想访问该匹配集合的话，你需要使用”this”，或者序号index作为该方法的第一个参数。<br />
<small class="red">jQuery1.4版本中实现代码：</small><br />
</p>

<div class="wp_codebox"><table><tr id="p1054101"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1054code101"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">'Index of this list item: '</span> <span style="color: #339933;">+</span> i<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>当然你可以给该回调函数传递第二个参数，比如是在使用设置类的DOM控制方法（如：.html()、.attr()等），你若想得到当前的值。<br />
<br /><small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1054102"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1054code102"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> currentHref<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> currentHref <span style="color: #339933;">+</span> <span style="color: #3366CC;">'?foo=bar'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p>正如你看到的一样，在使用.attr()和.css()方法是，当该方法的第一个是属性名称时，你可以将回调函数作为方法的第二参数。<br />
<br /><small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1054103"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1054code103"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'color'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> currentCssColor<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> i <span style="color: #339933;">%</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">'red'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'blue'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>十三、检测对象类型方法：</h3>
<p>jQuery1.4新版本在命名空间下新增了两个帮助型的方法，用来帮助你检测对象类型。</p>
<p>第一个方法：.isEmptyObject()用来判断一个对象是否是空对象，返回一个布尔类型的结果；<br />
第二个方法：.isPlainObject()用来判断一个对象是否是最原始的Javascript对象(该对象是否是通过{}或者new Object()创建)，同样也返回一个布尔类型的结果。<br />
<br /><small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1054104"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p1054code104"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">isEmptyObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// true</span>
jQuery.<span style="color: #660066;">isEmptyObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>foo<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// false</span>
&nbsp;
jQuery.<span style="color: #660066;">isPlainObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// true</span>
jQuery.<span style="color: #660066;">isPlainObject</span><span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// false</span>
jQuery.<span style="color: #660066;">isPlainObject</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// false</span></pre></td></tr></table></div>

</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/jQuery.isEmptyObject" class="p_l_5" rel="external">.isEmptyObject()</a><a href="http://api.jquery.com/jQuery.isPlainObject" class="p_5" rel="external">.isPlainObject()</a>方法的资料&#8230;</p>
<h3>十四、.Closest()方法扩展：</h3>
<p>扩展后的.Closest()支持数组选择器作为参数，这在遍历一个元素的祖先元素时非常有用。</p>

<div class="wp_codebox"><table><tr id="p1054105"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p1054code105"><pre class="html" style="font-family:monospace;">&lt; !DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;style&gt;&lt;/style&gt;
  &lt;script src=&quot;/scripts/jquery-1.4.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
	&lt;ul&gt;&lt;li&gt;&lt;/li&gt;&lt;li&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;script&gt;var close = $(&quot;li:first&quot;).closest([&quot;ul&quot;, &quot;body&quot;]);
$.each(close, function(i){
  $(&quot;li&quot;).eq(i).html( this.selector + &quot;: &quot; + this.elem.nodeName );
});&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>执行后的结果是：</p>

<div class="wp_codebox"><table><tr id="p1054106"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1054code106"><pre class="html" style="font-family:monospace;">    * ul: UL
    * body: BODY</pre></td></tr></table></div>

</p>
<p>另外该方法还支持使用上下文对象作为它的第二参数，也就是说你可以遍历任意上下文对象直到的元素的祖先元素。这个扩展使用的列子非常少，但在内部使用时非常的有效率。</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/closest" class="p_5" rel="external">.closest()</a>方法的资料&#8230;</p>
<h3>十四、新的事件机制（focusIn 、focusOut）：</h3>
<p>新版本中若要给事件对象委派”focus”和”blur”事件，也可以使用.focusIn()和.focusOut()方法（它们是一一对应的）。更加重要的是focus和blur事件不支持.live()方法委派，但focusIn和focusOut事件是支持.live()方法委派。<br />
<br /><small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1054107"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p1054code107"><pre class="javascript" style="font-family:monospace;">   jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form'</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">focusin</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>
        jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'focused'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    .<span style="color: #660066;">focusout</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>
        jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'focused'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p1054108"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p1054code108"><pre class="javascript" style="font-family:monospace;">   jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'focusin'</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>
        jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'focused'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    .<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'focusout'</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>
        jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'focused'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/focusin" class="p_l_5" rel="external">.focusin()</a><a href="http://api.jquery.com/focusout" class="p_5" rel="external">.focusin()</a>方法的资料&#8230;</p>
<p>文章总结翻译来自：<a href="http://net.tutsplus.com/tutorials/javascript-ajax/jquery-1-4-released-the-15-new-features-you-must-know/" rel="external">http://net.tutsplus.com/tutorials/javascript-ajax/jquery-1-4-released-the-15-new-features-you-must-know/</a></p>
<p>更多的API文档资料请阅读：<a href="http://api.jquery.com/" rel="external">http://api.jquery.com/</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年01月20日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a> (6)</li><li>2010年03月8日 -- <a href="http://www.ihiro.org/css3-basic" title="CSS:CSS3基础（附图）">CSS:CSS3基础（附图）</a> (12)</li><li>2009年12月18日 -- <a href="http://www.ihiro.org/10-javascript-tips" title="Javascript:10个Javscript编程的技巧">Javascript:10个Javscript编程的技巧</a> (4)</li><li>2009年12月16日 -- <a href="http://www.ihiro.org/jquery-once-through-the-event-delegate-to-bind-a-variety-of-time-in-order-to-reduce-the-event-of-redundancy" title="jQuery:通过事件委派一次绑定多种事件，以减少事件冗余">jQuery:通过事件委派一次绑定多种事件，以减少事件冗余</a> (7)</li><li>2009年12月1日 -- <a href="http://www.ihiro.org/how-to-custom-alias-in-plugins-and-page-code" title="jQuery:如何在页面和插件代码中自定义别名">jQuery:如何在页面和插件代码中自定义别名</a> (5)</li><li>2009年11月30日 -- <a href="http://www.ihiro.org/coding-clean-and-rich-semantic-html" title="HTML:编写干净的且富有语义的html代码">HTML:编写干净的且富有语义的html代码</a> (13)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年08月6日 -- <a href="http://www.ihiro.org/drop-down-menu" title="jQuery:两个样式下拉菜单(click hover)">jQuery:两个样式下拉菜单(click hover)</a> (8)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>jQuery:1.4新版本中你应该知道的15个新特性(一)</title>
		<link>http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1</link>
		<comments>http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1#comments</comments>
		<pubDate>Wed, 20 Jan 2010 05:53:13 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[前端工程译文]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[译文]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=1028</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2010/01/jquery-1.4-logo-1.gif" alt="" title="jquery-1.4-logo-1" width="100" height="100" class="alignleft size-full wp-image-1043" />
<p>题外话：前两天回了一趟泰州，星期二上班后看到了两条比较重大的新闻：1.谷歌耍了我们这些谷歌迷们一把，决定不离开中国了；2.jQuery1.4新版本也正式上线了。</p>
<p>从<a href="http://net.tutsplus.com/" rel="external">Nettuts+</a>博客上看到了这票jQuery1.4新特性的总结性文章，该博总结了15条新的特性，便给出相应的实现代码。觉得不错，便整理后翻译过来供大家参考，并加入了1.32版本的实现方法进行比较性地学习。</p>
<p class="red">文章较长，分两篇文章发布，请关心者耐心阅读与等待！上篇包含特性1-8点，下篇9-15点隔一日再发布！</p>]]></description>
			<content:encoded><![CDATA[<p>题外话：前两天回了一趟泰州，星期二上班后看到了两条比较重大的新闻：1.谷歌耍了我们这些谷歌迷们一把，决定不离开中国了；2.jQuery1.4新版本也正式上线了。</p>
<p>从<a href="http://net.tutsplus.com/" rel="external">Nettuts+</a>博客上看到了这票jQuery1.4新特性的总结性文章，该博总结了15条新的特性，便给出相应的实现代码。觉得不错，便整理后翻译过来供大家参考，并加入了1.32版本的实现方法进行比较性地学习。</p>
<p class="red">文章较长，分两篇文章发布，请关心者耐心阅读与等待！上篇包含特性1-8点，下篇9-15点隔一日再发布！</p>
<h3>一、给jQuery(…)方法传递新的参数：</h3>
<p>jQuery()方法是jQuery库的核心方法之一，在1.32版本及早期的版本中，该方法是用来获取节点或者创建DOM对象的，它只支持一个参数。在使用来创建新的DOM对象时，我们若要给该DOM对象添加属性的话，只能通过attr()方法在后面追加，很是不方便，阅读起来也比较累。在jQuery1.4中，给jQuery方法新增了一个对象型的参数，用来创建新的DOM对象设置该DOM对象相应的属性。<br />
<br /><small class="red">jQuery1.32版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1028109"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p1028code109"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a&gt;&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    id<span style="color: #339933;">:</span> <span style="color: #3366CC;">'foo'</span><span style="color: #339933;">,</span>
    href<span style="color: #339933;">:</span> <span style="color: #3366CC;">'http://google.com'</span><span style="color: #339933;">,</span>
    title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Become a Googler'</span><span style="color: #339933;">,</span>
    rel<span style="color: #339933;">:</span> <span style="color: #3366CC;">'external'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Go to Google!'</span><span style="color: #009900;">&#41;</span>
   .<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
       fontWeight<span style="color: #339933;">:</span> <span style="color: #CC0000;">700</span><span style="color: #339933;">,</span>
       color<span style="color: #339933;">:</span> <span style="color: #3366CC;">'green'</span>
   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
   .<span style="color: #660066;">click</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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Foo has been clicked!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1028110"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p1028code110"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a /&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    id<span style="color: #339933;">:</span> <span style="color: #3366CC;">'foo'</span><span style="color: #339933;">,</span>
    href<span style="color: #339933;">:</span> <span style="color: #3366CC;">'http://google.com'</span><span style="color: #339933;">,</span>
    title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Become a Googler'</span><span style="color: #339933;">,</span>
    rel<span style="color: #339933;">:</span> <span style="color: #3366CC;">'external'</span><span style="color: #339933;">,</span>
    text<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Go to Google!'</span><span style="color: #339933;">,</span>
    css<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        fontWeight<span style="color: #339933;">:</span> <span style="color: #CC0000;">700</span><span style="color: #339933;">,</span>
        color<span style="color: #339933;">:</span> <span style="color: #3366CC;">'green'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    click<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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Foo has been clicked!'</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: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/jQuery/" class="p_5" rel="external">jQuery(…)</a>方法的资料&#8230;</p>
<h3>二、新增”until”系列方法：</h3>
<p>新增”until”系列方法中有三个方法：”nextUntil”, “prevUntil” 和”parentsUntil”，这些方法是用来获取符合条件内的DOM对象。中文你可以理解为“直到”的意思。<br />
<br /><small class="red">若有一段XHtml代码如下：</small></p>

<div class="wp_codebox"><table><tr id="p1028111"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1028code111"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Apple<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Banana<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Grape<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Strawberry<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Pear<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span>Peach<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>现在我想选取从含有apple的li到含有pear的li,则代码实现：<br />
<br /><small class="red">jQuery1.32版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1028112"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1028code112"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1028113"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1028code113"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul li:contains(Apple)'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">nextUntil</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':contains(Pear)'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>虽然上面两者的选取效果是一样的，但若现在我在含有apple的li到含有pear的li中间再添加内容的话，1.32版本的代码就需要修改了，而1.4版本的则可继续使用，也就说1.4版本的代码可用性和语义性增强了。</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/prevUntil/" class="p_l_5" rel="external">prevUntil</a>, <a href="http://api.jquery.com/nextUntil/" class="p_l_5" rel="external">nextUntil</a>, <a href="http://api.jquery.com/parentsUntil/" class="p_5" rel="external">parentsUntil</a>方法的资料&#8230;</p>
<h3>三、给事件对象一次绑定多个事件：</h3>
<p>1.4不再像1.32版本中那样链式地给一个时间对象绑定时间，现在你可以将多个时间归纳后绑定到一个方法中。<br />
<br /><small class="red">jQuery1.32版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1028114"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p1028code114"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#foo).bind('</span>click<span style="color: #3366CC;">', function() {
        // do something
}).bind('</span>mouseover<span style="color: #3366CC;">', function() {
        // do something
}).bind('</span>mouseout‘， <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: #006600; font-style: italic;">// do something</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1028115"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p1028code115"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#foo).bind({
    click: function() {
        // do something
    },
    mouseover: function() {
        // do something
    },
    mouseout: function() {
        // do something
    }
});</span></pre></td></tr></table></div>

<p>当然对.one()一次点击事件也是适用的哦！</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/bind/" class="p_5" rel="external">.bind(…)</a>方法的资料&#8230;</p>
<h3>四、Per-Property Easing动画效果</h3>
<p>在1.32版本中，我们使用animate()方法给对象添加动画效果时，特效很单一，只能再引入jquery.easing.js插件来丰富动画特效。在新版本1.4中将该插件集成到了jQuery库中，这样在使用过的过程中就更加地方便了。<br />
<br /><small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1028116"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1028code116"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#foo'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    left<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span>
    top<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'easeOutBounce'</span><span style="color: #009900;">&#93;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>当然也可以给附加的属性参数内添加动画效果，如：</p>

<div class="wp_codebox"><table><tr id="p1028117"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p1028code117"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#foo'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    left<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span>
    top<span style="color: #339933;">:</span> <span style="color: #CC0000;">500</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    duration<span style="color: #339933;">:</span> <span style="color: #CC0000;">2000</span><span style="color: #339933;">,</span>
    specialEasing<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        top<span style="color: #339933;">:</span> <span style="color: #3366CC;">'easeOutBounce'</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/animate/#per-property-easing" class="p_5" rel="external">per-property easing</a>的资料&#8230;</p>
<h3>五、新增live事件：</h3>
<p>在1.32版本中，live()方法只对click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, keydown, keypress, keyup这些时间提供了支持，而不支持也比较常用的focus和blur时间。在1.4版本中新增了submit, change, focus, blur四种时间的支持。其中focus对应的是focusin事件，而blur对应了focusout事件。<br />
<br /><small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1028118"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p1028code118"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'focusin'</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>
    <span style="color: #006600; font-style: italic;">// do something with this</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'focusout'</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>
    <span style="color: #006600; font-style: italic;">// do something with this</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>六、控制方法的上下文对象：</h3>
<p>1.4版本在jQuery命名空间下新增了一个名叫”proxy“的方法，该方法有两个参数：一个是作用域，一个是准备执行的处理方法。在Javascript中，this关键字很巧妙地自动执行父亲对象或某个DOM元素对象。当有时候我们希望this指向的不是一个DOM元素对象，而是希望它指向一个之前创建的对象。</p>
<p>举个列子，就很容易明白！比如，现在我们有一个app对象，该对象内部有一个”clickHandler“方法和一个命名为”config“的对象。代码如下：</p>

<div class="wp_codebox"><table><tr id="p1028119"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1028code119"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> app <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
    config<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        clickMessage<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Hi!'</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    clickHandler<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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">config</span>.<span style="color: #660066;">clickMessage</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></pre></td></tr></table></div>

<p>当我们调用app.clickHandler()方法时，app对象就有了自己的上下文对象：clickHandler方法中的this指向的是app对象。执行后会弹出内容为”Hi!“的提示框。若现在我希望将该app对象下的clickHandler方法绑定在一个超链接上，如下：</p>

<div class="wp_codebox"><table><tr id="p1028120"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1028code120"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span> app.<span style="color: #660066;">clickHandler</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>而此时，当我们点击该超链接时，app对象下的clickHandler方法并不会执行，用Firebug测试则会提示”app.clickHandler is not a function!”。原因在于jQuery（以及绝大部分的事件对象）默认地将事件对象作为了该clickHandler方法的上下文对象，也就是此时this指向了a超链接标签元素。而我们的实际愿望是希望this执行app对象，那么1.4中我们就可以使用新增的proxy()方法来处理这一问题。代码如下：</p>

<div class="wp_codebox"><table><tr id="p1028121"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1028code121"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span>
    <span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span>
    jQuery.<span style="color: #660066;">proxy</span><span style="color: #009900;">&#40;</span>app<span style="color: #339933;">,</span> <span style="color: #3366CC;">'clickHandler'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>这样执行后提示框就会正常地弹出了。proxy()方法返回的是一个包装后的方法，它将执行你所期望的对象（通过第一个参数传递）。这在其他上下文对象中也很实用，比如给其他方法或插件传递回调函数。</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/jQuery.proxy" class="p_5" rel="external">jQuery.proxy()</a>方法的资料&#8230;</p>
<h3>七、延迟动画队列：</h3>
<p>在平时编写代码时，你或许发现有一个动画效果还没完成呢，下面的代码就已经执行完了。而我们希望的是等动画效果执行完成后或执行一段时间后再执行后面的代码。1.4版本中新增了delay()方法来延迟代码的执行。<br />
<br /><small class="red">jQuery1.32版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1028122"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1028code122"><pre class="javascript" style="font-family:monospace;">setTimeout<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">500</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>
        <span style="color: #006600; font-style: italic;">// do something</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><small class="red">jQuery1.4版本中实现代码：</small></p>

<div class="wp_codebox"><table><tr id="p1028123"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1028code123"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#foo'</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// Slide down</span>
    .<span style="color: #660066;">delay</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// Do nothing for 200 ms</span>
    .<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Fade in</span></pre></td></tr></table></div>

<p>若你希望延迟一个动画队列比默认的“fx”(queue()函数的默认参数)还要慢的话，你只需要将这个queue的变量名当作delay()方法的第二个参数传递即可。</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/delay" class="p_5" rel="external">.delay(&#8230;)</a>方法的资料&#8230;</p>
<h3>八、判断一个DOM父对象中是否含有某个匹配的子对象：</h3>
<p>1.4中新增了一个过滤型的方法has()来判断某个对象是否在某个标签或集合内出现过。该方法将返回在标签中出现的所有匹配子对象的集合，至少会包含一个子对象。若没有找到匹配子对象，则返回的是一个空的集合。</p>

<div class="wp_codebox"><table><tr id="p1028124"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1028code124"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">has</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>当然jQuery1.32版本中的.contains()方法其实也可以达到同样的效果，1.4版本又对.contains()进行了完善。在1.4版本中通过给.contains()方法传递两个DOM对象参数，从而判断第二个参数对象是否在第一个参数对象中。代码如下：</p>

<div class="wp_codebox"><table><tr id="p1028125"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1028code125"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">contains</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">documentElement</span><span style="color: #339933;">,</span> document.<span style="color: #660066;">body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Returns true - &lt;body&gt; is within &lt;html&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;&lt;/</span>body<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</p>
<p>&gt;&gt;&gt;&gt;阅读更多关于<a href="http://api.jquery.com/has/" class="p_l_5" rel="external">.has(…)</a>，<a href="http://api.jquery.com/jQuery.contains/" class="p_5" rel="external">jQuery.contains(…)</a>方法的资料&#8230;</p>
<p style="color:#090;">剩余的7点新特性隔一日发布！敬请期待吧，呵呵。</p>
<p>文章总结翻译来自：<a href="http://net.tutsplus.com/tutorials/javascript-ajax/jquery-1-4-released-the-15-new-features-you-must-know/" rel="external">http://net.tutsplus.com/tutorials/javascript-ajax/jquery-1-4-released-the-15-new-features-you-must-know/</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li><li>2010年03月8日 -- <a href="http://www.ihiro.org/css3-basic" title="CSS:CSS3基础（附图）">CSS:CSS3基础（附图）</a> (12)</li><li>2009年12月18日 -- <a href="http://www.ihiro.org/10-javascript-tips" title="Javascript:10个Javscript编程的技巧">Javascript:10个Javscript编程的技巧</a> (4)</li><li>2009年12月16日 -- <a href="http://www.ihiro.org/jquery-once-through-the-event-delegate-to-bind-a-variety-of-time-in-order-to-reduce-the-event-of-redundancy" title="jQuery:通过事件委派一次绑定多种事件，以减少事件冗余">jQuery:通过事件委派一次绑定多种事件，以减少事件冗余</a> (7)</li><li>2009年12月1日 -- <a href="http://www.ihiro.org/how-to-custom-alias-in-plugins-and-page-code" title="jQuery:如何在页面和插件代码中自定义别名">jQuery:如何在页面和插件代码中自定义别名</a> (5)</li><li>2009年11月30日 -- <a href="http://www.ihiro.org/coding-clean-and-rich-semantic-html" title="HTML:编写干净的且富有语义的html代码">HTML:编写干净的且富有语义的html代码</a> (13)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年08月6日 -- <a href="http://www.ihiro.org/drop-down-menu" title="jQuery:两个样式下拉菜单(click hover)">jQuery:两个样式下拉菜单(click hover)</a> (8)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Javascript:10个Javscript编程的技巧</title>
		<link>http://www.ihiro.org/10-javascript-tips</link>
		<comments>http://www.ihiro.org/10-javascript-tips#comments</comments>
		<pubDate>Fri, 18 Dec 2009 09:45:50 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[Pure Javascript]]></category>
		<category><![CDATA[前端工程译文]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[译文]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=941</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/12/javascript-tips.png" alt="javascript-tips" title="javascript-tips" width="100" height="100" class="alignleft size-full wp-image-951" />
<p>今天在<a href="http://www.impressivewebs.com/" rel="external">Blog：Impressive Webs</a>上看到这篇总结了10个Javascript技巧的文章。觉得比较受用，便简约地理解后翻译了给需要的朋友学习学习。</p>
<p>文章中的10条小技巧或许对大家来说已经是了然于胸了，但有时候编程晕头晕脑的，不经意间就会忘记。所以在平时的编程过程中养成一个良好的编程习惯是一个程序员最基础的素质要求。只要多练、多看、多学习，我们的编程技术就会越来越高明的！</p>
<p>该文整理来自：<a href="http://www.impressivewebs.com/10-javascript-quick-tips-and-best-practices/" rel="external">Impressive Webs:10 JavaScript Quick Tips and Best Practices</a></p>]]></description>
			<content:encoded><![CDATA[<p>今天在<a href="http://www.impressivewebs.com/" rel="external">Blog：Impressive Webs</a>上看到这篇总结了10个Javascript技巧的文章。觉得比较受用，便简约地理解后翻译了给需要的朋友学习学习。</p>
<h3>1.外部引入js文件时，使用defer属性供IE浏览器解析</h3>
<p>这个属性可加可不加，不管添加defer属性是不是一个好的编程技巧，但该属性在适当的时候会派上用场的。它的使用方法如下：</p>

<div class="wp_codebox"><table><tr id="p941126"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p941code126"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> defer<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;defer&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>添加defer属性的目的是在引入外部js文件时告诉Ie浏览器，只有在等页面加载完成后才执行引入的js文件中的js代码。当然这也可以通过一些比较好的代码实现，这些好的代码可以避免页面在没有加载完DOM就执行外部引入的js代码的问题。</p>
<p>注：defer属性只有IE浏览器才会支持。</p>
<h3>2.使用一个CDATA区域来避免XHTML Strict文件验证的错误</h3>
<p>XHTML Strict文件对页面中的标签和代码要求甚高，而js代码中常常出现运算符，而W3C验证XHTML Strict文件时，会认为页面js代码中的”< "、">“等运算符为一个标签的开始和结束，这样就会出现验证错误。</p>
<p>所以比较好的XHTML Strict文件中js编程习惯时给js代码外围加上一个CDATA区域，以达到该段js可以通过W3C验证。效果如下：</p>

<div class="wp_codebox"><table><tr id="p941127"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p941code127"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">//&lt; ![CDATA[</span>
<span style="color: #003366; font-weight: bold;">var</span> my_variable <span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>my_variable <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">50</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// do something here...</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">//]]&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</p>
<h3>3.避免使用Javascript的关键字来自定义变量</h3>
<p>每一种编程语言都有默认的一些关键字，在日常的代码编写过程中都因避免使用关键字作为自定义变量名。Javascript中的关键字有:</p>

<div class="wp_codebox"><table><tr id="p941128"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code" id="p941code128"><pre class="html" style="font-family:monospace;">break
case
catch
continue
default
delete
do
else
finally
for
function
if
in
instanceof
new
return
switch
this
throw
try
typeof
var
void
while
with</pre></td></tr></table></div>

</p>
<h3>4.避免使用Javascript的保留字来自定义变量</h3>
<p>同样每一种编程语言都有一定量的保留字，在自定义变量时也因避免使用这些保留字作为自定义变量名。Javascript的保留字有:</p>

<div class="wp_codebox"><table><tr id="p941129"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code" id="p941code129"><pre class="html" style="font-family:monospace;">abstract
boolean
byte
char
class
const
debugger
double
enum
export
extends
final
float
goto
implements
import
int
interface
long
native
package
private
protected
public
short
static
super
synchronized
throws
transient
volatile</pre></td></tr></table></div>

</p>
<h3>5.在自定义一个变量并赋予相应的类型后，在之后的代码中避免改变该变量的类型</h3>
<p>在Javascript编程中，如下的写法是不太理想的：</p>

<div class="wp_codebox"><table><tr id="p941130"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p941code130"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> my_variable <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;This is a String&quot;</span><span style="color: #339933;">;</span>
my_variable <span style="color: #339933;">=</span> <span style="color: #CC0000;">50</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>在第一行给my_variable变量赋予了一个String的类型，而在第二行却改变为了Integer类型，这样写是一个不好的习惯，应该避免这种情况的发生。
</p>
<h3>6.不要使用全局变量</h3>
<p>
为了防止可能发生的冲突，99％的情况下，使用var关键字最初声明变量和赋予该变量值。这将确保您的变量是局部的，而不是声明它们的功能函数之外。这样的话，在两个不同的函数体内使用相同的变量名就不会发生变量的冲突。而这里在函数体内定义的变量在函数执行完成后就会被取消，从而节省了命名空间。
</p>
<h3>7.Javascript对大小写敏感</h3>
<p>看下面的两个自定义变量，它们代表了两个不同的变量：</p>

<div class="wp_codebox"><table><tr id="p941131"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p941code131"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myVariable <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> myvariable <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;more data&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>所以，在日常的编写代码时，养成一个好的编程习惯，不要无意间因大小写的问题而定义了两个变量，其实你需要的只是一个变量。
</p>
<h3>8.使用switch声明来处理多种条件判断</h3>
<p>在多个条件判断代码的编写时，不要如下编写代码：</p>

<div class="wp_codebox"><table><tr id="p941132"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p941code132"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>example_variable <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;cyan&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// do something here...</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>example_variable <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;magenta&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// do something here...</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>example_variable <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;yellow&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// do something here...</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>example_variable <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;black&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// do something here...</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// do something here...</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>而是应该这样使用：</p>

<div class="wp_codebox"><table><tr id="p941133"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p941code133"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>example_variable<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;cyan&quot;</span><span style="color: #339933;">:</span>
		<span style="color: #006600; font-style: italic;">// do something here...</span>
		<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;magenta&quot;</span><span style="color: #339933;">:</span>
		<span style="color: #006600; font-style: italic;">// do something here...</span>
		<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;yellow&quot;</span><span style="color: #339933;">:</span>
		<span style="color: #006600; font-style: italic;">// do something here...</span>
		<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">&quot;black&quot;</span><span style="color: #339933;">:</span>
		<span style="color: #006600; font-style: italic;">// do something here...</span>
		<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
		<span style="color: #006600; font-style: italic;">// do something here...</span>
		<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>上面的两端代码执行的结果是一样的，但第二种使用swicth编写的代码便于阅读、管理和修改。
</p>
<h3>9.使用try-catch，以防止向用户显示错误</h3>
<p>将需要执行的代码包含在try-catch中，这样用户就永远看不多Javascript的报错信息。如下：</p>

<div class="wp_codebox"><table><tr id="p941134"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p941code134"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
	nonExistentFunction<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: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>error<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	document.<span style="color: #000066; font-weight: bold;">write</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;An error has occured.&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>在上面的代码中我试图去调用一个实际不存在的函数来产生一个错误。而浏览器则不会显示“not an object” 或者 “object expected”错误，而是现实了我在catch体内自定义的错误信息。当然你也可以在catch体内不懈任何代码，这样什么错误信息都不会输出。或者也可以在catch体内调用一个自定义的捕获错误的函数，以便调试其中的错误。
</p>
<p>当然，错误也有可能来自开发人员本身代码的错误，所以在代码中加上适当的注释信息是必不可少的。</p>
<h3>10.使用简约的多行注释对代码进行说明</h3>
<p>在Javascript中，注释有单行注释和多行注释之分。而有时候的注释文字很长时，良好的习惯是将注释文字放在多行中，以便于阅读。</p>

<div class="wp_codebox"><table><tr id="p941135"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p941code135"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
 * 我是多行注释 ...
 * 注释..
 * 注释...
 * 注释...
 * 注释...
 */</span></pre></td></tr></table></div>

</p>
<p><strong>总结：</strong>上面的10条小技巧或许对大家来说已经是了然于胸了，但有时候编程晕头晕脑的，不经意间就会忘记。所以在平时的编程过程中养成一个良好的编程习惯是一个程序员最基础的素质要求。只要多练、多看、多学习，我们的编程技术就会越来越高明的！</p>
<p>该文整理来自：<a href="http://www.impressivewebs.com/10-javascript-quick-tips-and-best-practices/" rel="external">Impressive Webs:10 JavaScript Quick Tips and Best Practices</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li><li>2010年12月30日 -- <a href="http://www.ihiro.org/javascript-getweek-by-date" title="Javascript:根据指定日期获得星期数">Javascript:根据指定日期获得星期数</a> (23)</li><li>2010年11月22日 -- <a href="http://www.ihiro.org/text-range" title="Range:文本框选区学习笔记">Range:文本框选区学习笔记</a> (16)</li><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年03月8日 -- <a href="http://www.ihiro.org/css3-basic" title="CSS:CSS3基础（附图）">CSS:CSS3基础（附图）</a> (12)</li><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li><li>2010年01月20日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a> (6)</li><li>2009年11月30日 -- <a href="http://www.ihiro.org/coding-clean-and-rich-semantic-html" title="HTML:编写干净的且富有语义的html代码">HTML:编写干净的且富有语义的html代码</a> (13)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/10-javascript-tips/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>jQuery:通过事件委派一次绑定多种事件，以减少事件冗余</title>
		<link>http://www.ihiro.org/jquery-once-through-the-event-delegate-to-bind-a-variety-of-time-in-order-to-reduce-the-event-of-redundancy</link>
		<comments>http://www.ihiro.org/jquery-once-through-the-event-delegate-to-bind-a-variety-of-time-in-order-to-reduce-the-event-of-redundancy#comments</comments>
		<pubDate>Wed, 16 Dec 2009 03:42:39 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[前端工程]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=932</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/12/tooltips-logo.png" alt="tooltips-logo" title="tooltips-logo" width="100" height="100" class="alignleft size-full wp-image-938" />
<p>jQuery的最大特色之一就是方法连缀写法，这样的书写方式使得阅读起来更加方便。于是乎，在日常的开发中大量使用连缀写法，而事件方法连缀就是一个特例。若给一个Dom对象使用了绑定了多个事件，便于阅读和书写，习惯了使用连缀写法，但这样的书写方式会造成时间的冗余。</p>
<h3>1.事件冗余：多个事件方法中多次调用相同的代码</h3>
<h3>2.事件委派：一次性绑定多个事件，根据事件类别委派相应的操作</h3>]]></description>
			<content:encoded><![CDATA[<p>jQuery的最大特色之一就是方法连缀写法，这样的书写方式使得阅读起来更加方便。于是乎，在日常的开发中大量使用连缀写法，而事件方法连缀就是一个特例。若给一个Dom对象使用了绑定了多个事件，便于阅读和书写，习惯了使用连缀写法，但这样的书写方式会造成时间的冗余。</p>
<h3>1.事件冗余：多个事件方法中多次调用相同的代码</h3>
<p>下面的代码是一个事件方法连缀的写法：</p>

<div class="wp_codebox"><table><tr id="p932136"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code" id="p932code136"><pre class="javascript" style="font-family:monospace;">jQuery<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: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div id=&quot;livetip&quot;&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> tipTitle <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mytable'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseover'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> $link <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">target</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">closest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$link.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> link <span style="color: #339933;">=</span> $link<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			tipTitle <span style="color: #339933;">=</span> link.<span style="color: #660066;">title</span><span style="color: #339933;">;</span>
			link.<span style="color: #660066;">title</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#livetip'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				top<span style="color: #339933;">:</span> event.<span style="color: #660066;">pageY</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">,</span>
				left<span style="color: #339933;">:</span> event.<span style="color: #660066;">pageX</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">12</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
			.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div&gt;'</span> <span style="color: #339933;">+</span> tipTitle <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/div&gt;&lt;div&gt;'</span> <span style="color: #339933;">+</span> link.<span style="color: #660066;">href</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span>
			.<span style="color: #660066;">show</span><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: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseout'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> $link <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">target</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">closest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$link.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$link.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #339933;">,</span> tipTitle<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#livetip'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><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: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mousemove'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> $link <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">target</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">closest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> $link.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#livetip'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				top<span style="color: #339933;">:</span> event.<span style="color: #660066;">pageY</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">,</span>
				left<span style="color: #339933;">:</span> event.<span style="color: #660066;">pageX</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">12</span>
			<span style="color: #009900;">&#125;</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>其中第5|6行、第18|19行、第24|25行多次地使用了同样的一段代码去判断事件对象是否存在。这不管是从代码效率还是代码文件大小的方面来说都是不合理的方法。
</p>
<h3>2.事件委派：一次性绑定多个事件，根据事件类别委派相应的操作</h3>
<p>为了更好地优化上面的代码，可以通过事件委派来修改代码，修改后的代码如下：</p>

<div class="wp_codebox"><table><tr id="p932137"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code" id="p932code137"><pre class="javascript" style="font-family:monospace;">jQuery<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> $liveTip <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div id=&quot;livetip&quot;&gt;&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> tipTitle <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mytable'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mouseover mouseout mousemove'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	  <span style="color: #003366; font-weight: bold;">var</span> $link <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">target</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">closest</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>$link.<span style="color: #660066;">length</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>
	  <span style="color: #003366; font-weight: bold;">var</span> link <span style="color: #339933;">=</span> $link<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">type</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'mouseover'</span> <span style="color: #339933;">||</span> event.<span style="color: #660066;">type</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'mousemove'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$liveTip.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		  top<span style="color: #339933;">:</span> event.<span style="color: #660066;">pageY</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">,</span>
		  left<span style="color: #339933;">:</span> event.<span style="color: #660066;">pageX</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">12</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">type</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'mouseover'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		tipTitle <span style="color: #339933;">=</span> link.<span style="color: #660066;">title</span><span style="color: #339933;">;</span>
		link.<span style="color: #660066;">title</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
		$liveTip.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div&gt;'</span> <span style="color: #339933;">+</span> tipTitle <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/div&gt;&lt;div&gt;'</span> <span style="color: #339933;">+</span> link.<span style="color: #660066;">href</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span>
			.<span style="color: #660066;">show</span><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: #339933;">;</span>
&nbsp;
	  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>event.<span style="color: #660066;">type</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'mouseout'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$liveTip.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>tipTitle<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			link.<span style="color: #660066;">title</span> <span style="color: #339933;">=</span> tipTitle<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>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>该段代码中一次性地将多个事件绑定到一个待处理的DOM对象之上，在代码的内部通过判断事件的类别来委派不同的处理代码。这样可以避免代码的重复定义，以达到避免时间冗余的效果。
</p>
<p>以上两种代码的执行后的效果是完全一样的，相信大家一眼就可以看中哪一种代码的执行效率更加的快速吧！</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/event_delegation/event_delegation.rar" class="download">download</a><a href="http://www.ihiro.org/cases/event_delegation/" rel="external" class="demo">demo</a></p>
<p><strong style="color:#090;">以上的代码来自：<a href="http://www.learningjquery.com/2009/12/binding-multiple-events-to-reduce-redundancy-with-event-delegation-tooltips" rel="external">Learning jQuery:Binding Multiple Events to Reduce Redundancy with Event-Delegation Tooltips</a></strong></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li><li>2010年01月20日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a> (6)</li><li>2009年12月1日 -- <a href="http://www.ihiro.org/how-to-custom-alias-in-plugins-and-page-code" title="jQuery:如何在页面和插件代码中自定义别名">jQuery:如何在页面和插件代码中自定义别名</a> (5)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年08月6日 -- <a href="http://www.ihiro.org/drop-down-menu" title="jQuery:两个样式下拉菜单(click hover)">jQuery:两个样式下拉菜单(click hover)</a> (8)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/jquery-once-through-the-event-delegate-to-bind-a-variety-of-time-in-order-to-reduce-the-event-of-redundancy/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>jQuery:如何在页面和插件代码中自定义别名</title>
		<link>http://www.ihiro.org/how-to-custom-alias-in-plugins-and-page-code</link>
		<comments>http://www.ihiro.org/how-to-custom-alias-in-plugins-and-page-code#comments</comments>
		<pubDate>Tue, 01 Dec 2009 14:03:47 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[前端工程]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=860</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/12/jquery-plugins.gif" alt="jquery-plugins" title="jquery-plugins" width="100" height="100" class="alignleft size-full wp-image-868" />
<p>众所周知，jQuery是采用$符号作为库的别名，但若是和其他类型的库一直使用是，其他库也有用$符号作为别名的，这样就会引起函数的冲突。所以更多的时间是建议大家使用jQuery来做为别名，或者自定义别名。该片文章重点地讲述了如何在页面代码和插件代码中自定义别名，以便于其他库的兼容，为之后的插件开发之旅铺垫道路！</p>
<h3>1.在页面使用代码中如何自定义别名；</h3>
<h3>2.在插件代码中如何自定义别名。</h3>]]></description>
			<content:encoded><![CDATA[<p>众所周知，jQuery是采用$符号作为库的别名，但若是和其他类型的库一直使用是，其他库也有用$符号作为别名的，这样就会引起函数的冲突。所以更多的时间是建议大家使用jQuery来做为别名，或者自定义别名。该片文章重点地讲述了如何在页面代码和插件代码中自定义别名，以便于其他库的兼容，为之后的插件开发之旅铺垫道路！</p>
<h3>1.在页面使用代码中如何自定义别名</h3>
<p>通常，我们是这样开始jQuery库的使用的：</p>

<div class="wp_codebox"><table><tr id="p860138"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p860code138"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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: #006600; font-style: italic;">//一些代码</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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: #006600; font-style: italic;">//一些代码</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>但是，若遇到了使用其他非jQuery库的情况，就需要对上面的代码进行改动了，所以兼容性不够好。比较好的方法是将$符号写全（jQuery）：</p>

<div class="wp_codebox"><table><tr id="p860139"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p860code139"><pre class="javascript" style="font-family:monospace;">jQuery<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: #006600; font-style: italic;">//一些代码</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>但是大家或许发现了，这样写的话，以后查找dom、或调用jQuery库中的函数，都需要写jQuery(&#8216;p&#8217;)、jQuery.trim()。是否觉得比较麻烦，还是觉得$符号好用呢？
</p>
<p>那么为你来介绍如何在页面代码中自定义别名的方法吧。格式如下：</p>

<div class="wp_codebox"><table><tr id="p860140"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p860code140"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>hiro<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">//在内部我就可以这样使用,来弹出我当前使用浏览器的版本号</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>hiro.<span style="color: #660066;">browser</span>.<span style="color: #660066;">version</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>只需要在function中传入一个自定义的参数，该参数就是你的自定义别名了。该别名可以随意地自定义，当然可以使用$符号来自定义了，格式如下：</p>

<div class="wp_codebox"><table><tr id="p860141"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p860code141"><pre class="javascript" style="font-family:monospace;">jQuery<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: #006600; font-style: italic;">//在内部我就可以这样使用,来弹出我当前使用浏览器的版本号</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">browser</span>.<span style="color: #660066;">version</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>这样使用的好处是，即使你在引入新的库后，也不会和新库产生冲突。
</p>
<h3>2.在插件代码中如何自定义别名</h3>
<p>插件的实现原理就是将所有的插件代码都写在一个方法体内，然后执行即可。就像这样：</p>

<div class="wp_codebox"><table><tr id="p860142"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p860code142"><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: #006600; font-style: italic;">// 这里可以写插件的代码</span>
  <span style="color: #003366; font-weight: bold;">var</span> xyz<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// xyz 不是一个全局变量，他只在该方法体内可以获得</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: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 该方法会立即执行（这里用到了匿名函数的概念）</span></pre></td></tr></table></div>

<p>这里多余的括号是必须的，因为你若不加括号的话，匿名函数就得不到执行。
</p>
<p>那么在插件中自定义别名就很简单了，和在页面中自定义别名类似，格式如下：</p>

<div class="wp_codebox"><table><tr id="p860143"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p860code143"><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: #006600; font-style: italic;">// 这里可以写插件的代码</span>
  <span style="color: #003366; font-weight: bold;">var</span> xyz<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// xyz 不是一个全局变量，他只在该方法体内可以获得</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>在上面的我给方法传入一个jQuery的参数，是因为该方法是对jQuery库的扩展，那么在该方法体内就可以调用jQuery库中的函数；若不传入，则无法调用jQuery库
</p>
<h3>一个小的插件编写技巧：</h3>
<p>在我阅读国外的开发人员编写的插件时，发现很多的插件都会在代码的开始部分加上一个分号，格式如下：</p>

<div class="wp_codebox"><table><tr id="p860144"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p860code144"><pre class="javascript" style="font-family:monospace;"><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: #006600; font-style: italic;">// 这里可以写插件的代码</span>
  <span style="color: #003366; font-weight: bold;">var</span> xyz<span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// xyz 不是一个全局变量，他只在该方法体内可以获得</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>我猜测这是因为很多的插件在代码的最前面会加上一些版权信息和使用方法的注释信息，加一个分号是为了防止注释结束遗忘吧，也告示着插件代码的开始！(<strong style="color:#f60;">个人猜测，仅供参考！</strong>)
</p>
<p>具体的代码实现格式和运用可以阅读<a href="http://www.ihiro.org/cases/js/jquery-tooltip/jquery.tooltip.js" rel="external">jQuery.tooltips.js</a>的源代码，他的编写方式比较“正统”！</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li><li>2010年01月20日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a> (6)</li><li>2009年12月16日 -- <a href="http://www.ihiro.org/jquery-once-through-the-event-delegate-to-bind-a-variety-of-time-in-order-to-reduce-the-event-of-redundancy" title="jQuery:通过事件委派一次绑定多种事件，以减少事件冗余">jQuery:通过事件委派一次绑定多种事件，以减少事件冗余</a> (7)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年08月6日 -- <a href="http://www.ihiro.org/drop-down-menu" title="jQuery:两个样式下拉菜单(click hover)">jQuery:两个样式下拉菜单(click hover)</a> (8)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/how-to-custom-alias-in-plugins-and-page-code/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>HTML:编写干净的且富有语义的html代码</title>
		<link>http://www.ihiro.org/coding-clean-and-rich-semantic-html</link>
		<comments>http://www.ihiro.org/coding-clean-and-rich-semantic-html#comments</comments>
		<pubDate>Mon, 30 Nov 2009 03:44:08 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[CSS、XHTML]]></category>
		<category><![CDATA[前端工程译文]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[译文]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=845</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/cleaner-coding.gif" alt="cleaner-coding" title="cleaner-coding" width="100" height="100" class="alignleft size-full wp-image-855" />
<p>如果你是一个使用div标签做任何事的家伙，那么这篇文章将对你十分有益。该问重点讲述了如何通过使用富有语义的标签和最少的div标记来编写干净的html代码。你是否曾经也试图去修改别人的一些html模板，那么你一定会被代码里那些肮脏的标签所抓狂。编写干净的html代码，不仅对你自己有益，而且对你的团队也有益。他将大大地节约了你的开发与错误调试时间（特别是比较大的一些项目）。</p>
<p>1.尽可能少地使用div标签；<br />
2.使用div标签来控制页面的整体布局，如头部，内容部，侧边栏，底部等；<br />
3.内容必须包含在对应的语义标签内，而不是包含在div内；<br />
4.格式化你的源代码并且在结束标签处给出对应的注释语言。</p>
<p>该文翻译自：<a href="http://www.webdesignerwall.com/tutorials/coding-clean-and-semantic-templates/" rel="external">WebDesignWall: Coding Clean and Semantic Templates</a></p>]]></description>
			<content:encoded><![CDATA[<p>如果你是一个使用div标签做任何事的家伙，那么这篇文章将对你十分有益。该问重点讲述了如何通过使用富有语义的标签和最少的div标记来编写干净的html代码。你是否曾经也试图去修改别人的一些html模板，那么你一定会被代码里那些肮脏的标签所抓狂。编写干净的html代码，不仅对你自己有益，而且对你的团队也有益。他将大大地节约了你的开发与错误调试时间（特别是比较大的一些项目）。</p>
<h3>1.去除不必要的div标签：</h3>
<p>我曾经看到好多的人将form和ul标签都包含在了div标签内。为什么要写一个不必要的标签呢。你可以给适当的选择器赋予css规则，这样也可以达到同样的效果。</p>
<h4>例子一：</h4>
<p>下面的列子将展示给你如何删除多余的div标签，而将css规则声明给内部的form标签。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_01_div-form.gif" alt="clean_html_01_div-form" title="clean_html_01_div-form" width="470" height="259" class="aligncenter size-full wp-image-846" /></p>
<h4>例子二：</h4>
<p>有时侯我们会将一些内容用额外的div标签包含起来，其目的是为了严格地控制布局的空隙。在这个例子的左边使用了一个&lt;div class=”box”&gt;来控制两个box之间的外边距margin。但如果每个box内都有一个标题h4，那么我们可以通过h4标签来控制外间距margin，从而可以删除掉多余的&lt;div class=”box”&gt;标签。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_02_div-sidebox.gif" alt="clean_html_02_div-sidebox" title="clean_html_02_div-sidebox" width="470" height="267" class="aligncenter size-full wp-image-847" /></p>
<h3>2.使用富有语义的标记：</h3>
<p>你必须时刻都使用富有语义的标记来编写html代码（如：h1用作标题，p用作文章段落，ul则用于列表项）。那么，即使你的css文件没有引入或者没有被支持，你的html文档看起来也是富有意义的。</p>
<h4>例子：</h4>
<p>下面的一张图片比较了使用div标记和使用富有语义的标记编写的一段html代码（没有css代码的支持）在浏览器中编译后的效果。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_03_semantic-markups.gif" alt="clean_html_03_semantic-markups" title="clean_html_03_semantic-markups" width="470" height="482" class="aligncenter size-full wp-image-848" /></p>
<h3>3.尽可能地少使用div标签：</h3>
<p>你是否看到过一些到处都是div的html文档，它是否让你非常地抓狂？是否你曾忘记关闭一个&lt;/div&gt;或者无意添加了一个打开的&lt;div&gt;标签呢？我确定绝大多数的开发者都曾有过这样的经验。所以你需要尽可能少地使用div标签。这样以后的调试和改错的过程就会变得更加容易。</p>
<h4>例子一：</h4>
<p>用p标签来替代div标签去包含一个面包屑导航。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_04_div-breadcrumb.gif" alt="clean_html_04_div-breadcrumb" title="clean_html_04_div-breadcrumb" width="470" height="130" class="aligncenter size-full wp-image-849" /></p>
<h4>例子二：</h4>
<p>下面的例子展示了如何通过css规则来将两个div标签替换成一个span标签。这两种写法得到的结果是完全一致的。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_05_div-date.gif" alt="clean_html_05_div-date" title="clean_html_05_div-date" width="470" height="500" class="aligncenter size-full wp-image-850" /></p>
<h3>4.格式化（缩进）你的代码：</h3>
<p>你在开发的过程中始终要格式化你的源代码（如缩进嵌套的标签），这样的可以方便以后的阅读和错误调试。如果你使用Adobe Dreamweaver的话，那么你可以很简单地去格式化源代码。方法：点击“命令”菜单下的“应用源代码”选项即可。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_06_format-code.gif" alt="clean_html_06_format-code" title="clean_html_06_format-code" width="470" height="203" class="aligncenter size-full wp-image-851" /></p>
<h3>5.在&lt;/div&gt;结束处给出相应的注释：</h3>
<p>当你编写一个平台模板(如：Wordpress主题)代码时，这些模板文件会被分割成多个不同的文件：如：index.php, header.php, sidebar.php, 和 footer.php。因此，你必须在&lt;/div&gt;结束处给出相应的注释。比如：当我看到&lt;/div&gt;&lt;!&#8211; /wrapper &#8211;&gt;时，我就知道这里是&lt;div id=”wrapper”&gt;标签的结束处。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_07_comment-code.gif" alt="clean_html_07_comment-code" title="clean_html_07_comment-code" width="470" height="122" class="aligncenter size-full wp-image-852" /></p>
<h3>总结：</h3>
<p>1.尽可能少地使用div标签；<br />
2.使用div标签来控制页面的整体布局，如头部，内容部，侧边栏，底部等；<br />
3.内容必须包含在对应的语义标签内，而不是包含在div内；<br />
4.格式化你的源代码并且在结束标签处给出对应的注释语言。</p>
<p>该文翻译自：<a href="http://www.webdesignerwall.com/tutorials/coding-clean-and-semantic-templates/" rel="external">WebDesignWall: Coding Clean and Semantic Templates</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年03月8日 -- <a href="http://www.ihiro.org/css3-basic" title="CSS:CSS3基础（附图）">CSS:CSS3基础（附图）</a> (12)</li><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li><li>2010年01月20日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a> (6)</li><li>2009年12月18日 -- <a href="http://www.ihiro.org/10-javascript-tips" title="Javascript:10个Javscript编程的技巧">Javascript:10个Javscript编程的技巧</a> (4)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/coding-clean-and-rich-semantic-html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</title>
		<link>http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board</link>
		<comments>http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board#comments</comments>
		<pubDate>Thu, 26 Nov 2009 15:30:43 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[案例分享]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[前端工程]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=835</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/noticeBox-thum.gif" alt="noticeBox-thum" title="noticeBox-thum" width="100" height="100" class="alignleft size-full wp-image-837" />
<p>昨天晚上收到<label style="color:#090; font-weight:bold;">随风同学</label>的求助邮件，说因上级的要求需要制作一个走马灯效果的公告栏，希望我可以帮助他解决。因看到邮件的时候都快要睡觉了，所以并没有立即处理。</p>
<p>今天早上到了公司，放开手边的工作，花了一点点时间给他制作了一个主流浏览器都兼容的走马灯公告栏。然后mail给他，但他过会儿回邮件说缺少鼠标悬停时停止的效果。于是乎有花了几分钟添加了相应的代码。到了下午快下班的时候，该同学又发来了邮件，说我的公告栏的效果有点欠缺，现在的效果和marquee标签<label style="color:#f60;">(该标签不符合W3C标准)</label>的效果一样，需要等内容上移完成后才会重复滚动，如果可以连续滚动的话那就完美了。</p>
<p>于是就在刚刚的时间我有花了几分钟的时间给他解决了，mail给他。不知道他是否还会有什么新的要求呢，期待啊！毕竟这对我来说也是一个挑战嘛，同时也帮助到了别人，何乐而不为呢！</p>]]></description>
			<content:encoded><![CDATA[<p>昨天晚上收到<label style="color:#090; font-weight:bold;">随风同学</label>的求助邮件，说因上级的要求需要制作一个走马灯效果的公告栏，希望我可以帮助他解决。因看到邮件的时候都快要睡觉了，所以并没有立即处理。</p>
<p>今天早上到了公司，放开手边的工作，花了一点点时间给他制作了一个主流浏览器都兼容的走马灯公告栏。然后mail给他，但他过会儿回邮件说缺少鼠标悬停时停止的效果。于是乎有花了几分钟添加了相应的代码。到了下午快下班的时候，该同学又发来了邮件，说我的公告栏的效果有点欠缺，现在的效果和marquee标签<label style="color:#f60;">(该标签不符合W3C标准)</label>的效果一样，需要等内容上移完成后才会重复滚动，如果可以连续滚动的话那就完美了。</p>
<p>于是就在刚刚的时间我有花了几分钟的时间给他解决了，mail给他。不知道他是否还会有什么新的要求呢，期待啊！毕竟这对我来说也是一个挑战嘛，同时也帮助到了别人，何乐而不为呢！</p>
<p>因为觉得功能差不多都实现了，所以也共享出来与大家分享，或许会对你有所帮助呢。</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/noticeBox/noticeBox.rar" class="download">download</a><a href="http://www.ihiro.org/cases/noticeBox/" rel="external" class="demo">demo</a></p>
<h3>1.Html代码：</h3>

<div class="wp_codebox"><table><tr id="p835145"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code" id="p835code145"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;container&quot;&gt;
    &lt;ul class=&quot;noticeList&quot;&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/wordpress-the-article-automatically-appear-as-two&quot; title=&quot;Wordpress:将文章自动显示为两列&quot;&gt;Wordpress:将文章自动显示为两列&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/film-2012-really-have-that-day-discovery-channel-expose-for-you&quot; title=&quot;电影:《2012》真的有那一天吗？探索频道为你揭露&quot;&gt;电影:《2012》真的有那一天吗？探索频道为你揭露&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/information-november-2009-programming-language-list&quot; title=&quot;资讯:2009年11月编程语言排行榜&quot;&gt;资讯:2009年11月编程语言排行榜&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/a-busy-week-for-rent-a-house-was-finally-gaoding&quot; title=&quot;租房:忙碌一周，房子终于搞定&quot;&gt;租房:忙碌一周，房子终于搞定&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/my-third-theme-innernews&quot; title=&quot;主题:我的第三个主题innerNews提供下载&quot;&gt;主题:我的第三个主题innerNews提供下载&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/my-first-plugin-scrolltop&quot; title=&quot;插件:我的第一个插件–简约的scrollTop滑动插件&quot;&gt;插件:我的第一个插件–简约的scrollTop滑动插件&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/celebrate-my-blog-pr-catapulted-3&quot; title=&quot;PageRank:庆贺我的博客PR连升3级&quot;&gt;PageRank:庆贺我的博客PR连升3级&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/myeclipse-8-and-registration-number&quot; title=&quot;软件:MyEclipse 8.0发布，附注册码&quot;&gt;软件:MyEclipse 8.0发布，附注册码&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/tv-leng-jian&quot; title=&quot;电视:《冷箭》，让我“失眠”的谍战片&quot;&gt;电视:《冷箭》，让我“失眠”的谍战片&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/hd-is-an-attitude&quot; title=&quot;下载:高清，是一种态度！&quot;&gt;下载:高清，是一种态度！&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<h3>2.CSS代码：</h3>

<div class="wp_codebox"><table><tr id="p835146"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p835code146"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span> Verdana<span style="color: #00AA00;">,</span> Geneva<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#666</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#container</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">180px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">250px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.noticeList</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">180px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inside</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">270px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.noticeList</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.noticeList</span> li a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#606060</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.noticeList</span> li a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#09F</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>3.JS代码：（备了部分注释，不懂的可以留言询问。）</h3>

<div class="wp_codebox"><table><tr id="p835147"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code" id="p835code147"><pre class="javascript" style="font-family:monospace;">jQuery<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;">function</span> ScrollAction<span style="color: #009900;">&#40;</span>listObj<span style="color: #339933;">,</span> listElem<span style="color: #339933;">,</span> speed<span style="color: #339933;">,</span> isSeries<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	<span style="color: #006600; font-style: italic;">//listObj为需要滚动的列表，  speed为滚动速度</span>
		<span style="color: #003366; font-weight: bold;">var</span> pos<span style="color: #339933;">,</span> top<span style="color: #339933;">,</span> aniTop<span style="color: #339933;">,</span> height<span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> id <span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">//记录setInterval的标记id</span>
&nbsp;
		pos <span style="color: #339933;">=</span> listObj.<span style="color: #660066;">position</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		top <span style="color: #339933;">=</span> pos.<span style="color: #660066;">top</span><span style="color: #339933;">;</span>			<span style="color: #006600; font-style: italic;">//列表的top</span>
		aniTop <span style="color: #339933;">=</span> top<span style="color: #339933;">;</span>				<span style="color: #006600; font-style: italic;">//记录当前运动时的top</span>
		height <span style="color: #339933;">=</span> listObj.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//列表的高度</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> scrollUp <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>
			aniTop<span style="color: #339933;">--;</span>
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isSeries<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	<span style="color: #006600; font-style: italic;">//isSeries变量控制是否连续滚动，false不连续，true连续</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>aniTop <span style="color: #339933;">==</span> <span style="color: #339933;">-</span>height<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	<span style="color: #006600; font-style: italic;">//不连续，滚动玩重新滚动</span>
					listObj.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'top'</span><span style="color: #339933;">:</span> top<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					aniTop <span style="color: #339933;">=</span> top<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: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>aniTop <span style="color: #339933;">==</span> <span style="color: #339933;">-</span>listObj.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	<span style="color: #006600; font-style: italic;">//连续滚动</span>
					<span style="color: #003366; font-weight: bold;">var</span> firstItem <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt; '</span> <span style="color: #339933;">+</span> listElem <span style="color: #339933;">+</span><span style="color: #3366CC;">'&gt;'</span> <span style="color: #339933;">+</span> listObj.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt; /'</span> <span style="color: #339933;">+</span> listElem <span style="color: #339933;">+</span><span style="color: #3366CC;">'&gt;'</span><span style="color: #339933;">;</span>
					listObj.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					listObj.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>firstItem<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					aniTop <span style="color: #339933;">=</span> <span style="color: #CC0000;">4</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>
			listObj.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'top'</span><span style="color: #339933;">:</span> aniTop <span style="color: #339933;">+</span> <span style="color: #3366CC;">'px'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> hover <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			listObj.<span style="color: #660066;">hover</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>
				clearInterval<span style="color: #009900;">&#40;</span>id<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: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				id <span style="color: #339933;">=</span> setInterval<span style="color: #009900;">&#40;</span>scrollUp<span style="color: #339933;">,</span> speed<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">start</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>
			id <span style="color: #339933;">=</span> setInterval<span style="color: #009900;">&#40;</span>scrollUp<span style="color: #339933;">,</span> speed<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			hover<span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> sa <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ScrollAction<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.noticeList'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'li'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">30</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	sa.<span style="color: #660066;">start</span><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;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p style="color:#f00;">使用时别忘了引入jQuery库哦，也希望大家给我提出意见，或功能扩充等要求。</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2010年11月25日 -- <a href="http://www.ihiro.org/css-position-hack" title="CSS:position属性定位总结">CSS:position属性定位总结</a> (28)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年03月8日 -- <a href="http://www.ihiro.org/css3-basic" title="CSS:CSS3基础（附图）">CSS:CSS3基础（附图）</a> (12)</li><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li><li>2010年01月20日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a> (6)</li><li>2009年12月16日 -- <a href="http://www.ihiro.org/jquery-once-through-the-event-delegate-to-bind-a-variety-of-time-in-order-to-reduce-the-event-of-redundancy" title="jQuery:通过事件委派一次绑定多种事件，以减少事件冗余">jQuery:通过事件委派一次绑定多种事件，以减少事件冗余</a> (7)</li><li>2009年12月1日 -- <a href="http://www.ihiro.org/how-to-custom-alias-in-plugins-and-page-code" title="jQuery:如何在页面和插件代码中自定义别名">jQuery:如何在页面和插件代码中自定义别名</a> (5)</li><li>2009年08月28日 -- <a href="http://www.ihiro.org/jquery-hot-pictures-showing-effects-of-rotation" title="jQuery:热点图片轮换展示效果">jQuery:热点图片轮换展示效果</a> (14)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>插件:我的第一个插件&#8211;简约的scrollTop滑动插件</title>
		<link>http://www.ihiro.org/my-first-plugin-scrolltop</link>
		<comments>http://www.ihiro.org/my-first-plugin-scrolltop#comments</comments>
		<pubDate>Mon, 02 Nov 2009 14:04:09 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[插件开发]]></category>
		<category><![CDATA[Hiro的项目]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=750</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/hiro-scrollTop-plugins.jpg" alt="hiro-scrollTop-plugins" title="hiro-scrollTop-plugins" width="100" height="100" class="alignleft size-full wp-image-754" />
<p>周末无事，便写了一个简约的scrollTop插件。在前面的文章（<a href="http://www.ihiro.org/jquery-scrolltop-plugins" rel="external">jQuery:Scrolltop滑动插件推荐（修正注释版）</a>）中，我曾介绍过一款我在网络收集的相关插件。但发现该作者的代码确实很繁琐，不是很优雅。而我的该scrollTop插件代码就那么十多行，代码非常简单，也非常实用，适合大众使用！</p>
<p>这也是算是我的jQuery插件开发之旅的开端吧，以后一有机会我就会陆续开发一些自己的插件，也尽量写一些简约的插件与大家分享。也希望有这方面的朋友可以多多交流。话不多说，上插件！</p>
<p style="color:#f00;">该插件的好处是无需在html源文件的头部添加任何标签，只需调用方法即可实现效果！</p>]]></description>
			<content:encoded><![CDATA[<p>周末无事，便写了一个简约的scrollTop插件。在前面的文章（<a href="http://www.ihiro.org/jquery-scrolltop-plugins" rel="external">jQuery:Scrolltop滑动插件推荐（修正注释版）</a>）中，我曾介绍过一款我在网络收集的相关插件。但发现该作者的代码确实很繁琐，不是很优雅。而我的该scrollTop插件代码就那么十多行，代码非常简单，也非常实用，适合大众使用！</p>
<p>这也是算是我的jQuery插件开发之旅的开端吧，以后一有机会我就会陆续开发一些自己的插件，也尽量写一些简约的插件与大家分享。也希望有这方面的朋友可以多多交流。话不多说，上插件！</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/downloads/PersonalPlugins/scrollTop/scrollTop.rar" class="download">download</a><a href="http://www.ihiro.org/downloads/PersonalPlugins/scrollTop/"  rel="external" class="demo">demo</a></p>
<h3>插件代码：</h3>

<div class="wp_codebox"><table><tr id="p750148"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code" id="p750code148"><pre class="javascript" style="font-family:monospace;">jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
&nbsp;
	scrollTop<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>params<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// 给出默认的参数值</span>
		<span style="color: #006600; font-style: italic;">// 默认情况下，不传参数，没有滑动效果：scrollAnimation = false</span>
		<span style="color: #006600; font-style: italic;">// 若只传一个参数scrollAnimation: true,则默认的速度是500</span>
		<span style="color: #003366; font-weight: bold;">var</span> scrollAnimation <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span> speed <span style="color: #339933;">=</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>params <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			scrollAnimation <span style="color: #339933;">=</span> params.<span style="color: #660066;">scrollAnimation</span><span style="color: #339933;">;</span>
			speed <span style="color: #339933;">=</span> params.<span style="color: #660066;">speed</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>speed <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">||</span> speed <span style="color: #339933;">==</span> <span style="color: #3366CC;">'normal'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				speed <span style="color: #339933;">=</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>speed <span style="color: #339933;">==</span> <span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				speed <span style="color: #339933;">=</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>speed <span style="color: #339933;">==</span> <span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				speed <span style="color: #339933;">=</span> <span style="color: #CC0000;">2000</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>
&nbsp;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">click</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><span style="color: #339933;">!</span>scrollAnimation<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				window.<span style="color: #660066;">scrollTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</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;">else</span> <span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html, body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>scrollTop<span style="color: #339933;">:</span> <span style="color: #3366CC;">'0'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> speed<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>参数说明：</h3>
<p>1. scrollAnimation 为布尔型， 控制是否需要动态滑动， 可选值：ture、false<br />
2. speed 控制滑动速度，只有scrollAnimation设置为true时才起到作用， 可选值：slow、normal、fast、任意数字</p>
<h3>使用方法：(假设有html文档中一个class为top的标签)</h3>
<p>1. 直接跳到顶部: <br />
 $(&#8216;.top&#8217;).scrollTop();</p>
<p>2. 以默认的速度滑行到顶部:	<br />
$(&#8216;.top&#8217;).scrollTop({&#8216;scrollAnimation&#8217;: &#8216;true&#8217;});<br />
或 $(&#8216;.top&#8217;).scrollTop({&#8216;scrollAnimation&#8217;: &#8216;true&#8217;, &#8216;speed&#8217;: &#8216;normal&#8217;});</p>
<p>3. 自定义速度滑行到顶部：可选值：slow、fast、任意数字<br />
$(&#8216;.top&#8217;).scrollTop({&#8216;scrollAnimation&#8217;: &#8216;true&#8217;, &#8216;speed&#8217;: &#8216;slow&#8217;});  移动到顶部的时间为2000毫秒<br />
$(&#8216;.top&#8217;).scrollTop({&#8216;scrollAnimation&#8217;: &#8216;true&#8217;, &#8216;speed&#8217;: &#8216;fast&#8217;});  移动到顶部的时间为200毫秒<br />
$(&#8216;.top&#8217;).scrollTop({&#8216;scrollAnimation&#8217;: &#8216;true&#8217;, &#8216;speed&#8217;: &#8217;1000&#8242;});  移动到顶部的时间为1000毫秒</p>
<h3>总结：</h3>
<p style="color:#f00;">该插件的好处是无需在html源文件的头部添加任何标签，只需调用方法即可实现效果！</p>
<p style="color:#f00;">另外，jQuery库请使用者自行根据路径添加&#8230;</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年10月21日 -- <a href="http://www.ihiro.org/jquery-plugin-recommended-maphighlight" title="jQuery:热区高亮maphighlight插件推荐">jQuery:热区高亮maphighlight插件推荐</a> (23)</li><li>2010年06月30日 -- <a href="http://www.ihiro.org/firebug-console-panel-function" title="Firebug:Javascript测试利器，Console面板函数详解">Firebug:Javascript测试利器，Console面板函数详解</a> (4)</li><li>2010年02月24日 -- <a href="http://www.ihiro.org/javascript-news-flash-header-tips" title="Javascript:新消息闪烁标题提示代码分享">Javascript:新消息闪烁标题提示代码分享</a> (7)</li><li>2009年08月21日 -- <a href="http://www.ihiro.org/jquery-scrolltop-plugins" title="jQuery:Scrolltop滑动插件推荐（修正注释版）">jQuery:Scrolltop滑动插件推荐（修正注释版）</a> (25)</li><li>2009年06月18日 -- <a href="http://www.ihiro.org/jquery-plugins-for-dw4" title="jQuery plugins for DW4">jQuery plugins for DW4</a> (2)</li><li>2011年11月25日 -- <a href="http://www.ihiro.org/firebug-extension-firequery" title="插件：Firebug扩展插件FireQuery">插件：Firebug扩展插件FireQuery</a> (2)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年08月12日 -- <a href="http://www.ihiro.org/sizzle-custom-selector" title="Sizzle:开源JS选择器，如何自定义选择器">Sizzle:开源JS选择器，如何自定义选择器</a> (31)</li><li>2010年05月21日 -- <a href="http://www.ihiro.org/dw-html5-extension" title="扩展:Adobe放出Dreamweaver CS5 HTML 5扩展包">扩展:Adobe放出Dreamweaver CS5 HTML 5扩展包</a> (16)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/my-first-plugin-scrolltop/feed</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Ajax:当前页面更改内容，前端实现</title>
		<link>http://www.ihiro.org/ajax-editing-in-placing</link>
		<comments>http://www.ihiro.org/ajax-editing-in-placing#comments</comments>
		<pubDate>Wed, 23 Sep 2009 04:26:22 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[案例分享]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[前端工程]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=677</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/09/Ajax-Editing-150x150.jpg" alt="Ajax-Editing" title="Ajax-Editing" width="100" height="100" class="alignleft wp-image-682" />
<p>相信大家有用过Google Doc或Flickr，或者一些SNS社区的图片添加描述信息的效果，他们是在点击了一段文字后出现一个输入框，在输入框内输入你要填写的内容，点击“确认”或者“发表”即可立即显示出来。</p>
<p>今天做的这个效果呢，就是其中的截取版本。为什么这么说呢，因为我的效果只实现了前端的更改后立即发布的效果，而没有实际的与服务器端交互，也没有将输入的内容添加到数据库中，主要是为大家介绍一下实现原理。</p>
<p class="color-red">注意：源代码中没有jQuery库文件，请下载查看代码的朋友根据源代码路径自行添加。</p>]]></description>
			<content:encoded><![CDATA[<p>相信大家有用过Google Doc或Flickr，或者一些SNS社区的图片添加描述信息的效果，他们是在点击了一段文字后出现一个输入框，在输入框内输入你要填写的内容，点击“确认”或者“发表”即可立即显示出来。</p>
<p>今天做的这个效果呢，就是其中的截取版本。为什么这么说呢，因为我的效果只实现了前端的更改后立即发布的效果，而没有实际的与服务器端交互，也没有将输入的内容添加到数据库中，主要是为大家介绍一下实现原理。</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/AjaxEditing/AjaxEditing.rar" class="download">download</a><a href="http://www.ihiro.org/cases/AjaxEditing/" class="demo">demo</a></p>
<h3>1.HTML代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p677149"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code" id="p677code149"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;container&quot;&gt;
  &lt;h1&gt;Ajax Editing&lt;/h1&gt;
  &lt;p&gt;鼠标移动到列表上，双击即可以进行编辑！&lt;/p&gt;
  &lt;div class=&quot;block&quot;&gt;
    &lt;h2&gt;一、电影列表&lt;/h2&gt;
    &lt;ul class=&quot;editable&quot;&gt;
      &lt;li&gt;《建国大业》，&lt;span class=&quot;color_red&quot;&gt;更新中...&lt;/span&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/film-eternal-beloved&quot;&gt;《爱有来生》&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/movie-coco-chanel&quot;&gt;《COCO Chanel》&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/one-night-in-supermarket&quot;&gt;《夜店》&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/the-legend-of-1900&quot;&gt;《海上钢琴师–1900的传说》&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/film-xinsushijian-feedback&quot;&gt;《新宿事件》&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;div class=&quot;block&quot;&gt;
    &lt;h2&gt;二、书籍列表&lt;/h2&gt;
    &lt;ul class=&quot;editable&quot;&gt;
      &lt;li&gt;《精通Javascript》&lt;/li&gt;
      &lt;li&gt;《jQuery基础教程》&lt;/li&gt;
      &lt;li&gt;《Flex入门到精通》&lt;/li&gt;
      &lt;li&gt;《PHP与MySQL Web开发》&lt;/li&gt;
      &lt;li&gt;《Google，你可以做什么》&lt;/li&gt;
      &lt;li&gt;《不抱怨的世界》&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>

</p>
<h3></h3>
<p>
<div class="wp_codebox"><table><tr id="p677150"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
</pre></td><td class="code" id="p677code150"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span>/<span style="color: #933;">20px</span> Georgia<span style="color: #00AA00;">,</span> <span style="color: #ff0000;">&quot;Times New Roman&quot;</span><span style="color: #00AA00;">,</span> Times<span style="color: #00AA00;">,</span> <span style="color: #993333;">serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#404040</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
h2 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">24px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.color_red</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F00</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#container</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">400px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">1%</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* 标题样式 */</span>
	<span style="color: #cc00cc;">#container</span> h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">32px</span> <span style="color: #ff0000;">&quot;Lucida Sans Unicode&quot;</span><span style="color: #00AA00;">,</span> <span style="color: #ff0000;">&quot;Lucida Grande&quot;</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
	.<span style="color: #993333;">block</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">180px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span> <span style="color: #933;">20px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* 列表li的样式 */</span>
	ul<span style="color: #6666ff;">.editable</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* 高亮当前编辑的列表li */</span>
	<span style="color: #6666ff;">.hover</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#E8F3FF</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* 高亮当前的input输入框 */</span>
	<span style="color: #6666ff;">.editInput</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">160px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#E8F3FF</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #808080; font-style: italic;">/* save和cancel按钮的效果，鼠标移动到上面的效果 */</span>
	<span style="color: #6666ff;">.btnSave</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.btnCancel</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#09F</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#36F</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.btnSave</span><span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.btnCancel</span><span style="color: #3333ff;">:hover  </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#36F</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#39F</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</p>
<h3>3. jQuery代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p677151"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code" id="p677code151"><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>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> oldText<span style="color: #339933;">,</span> newText<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//鼠标移动到列表li上后，添加一个高亮的背景</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.editable li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hover'</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: #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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hover'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'dblclick'</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>
&nbsp;
		<span style="color: #006600; font-style: italic;">//获得列表li中原先的html代码</span>
		oldText <span style="color: #339933;">=</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: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&quot;/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&amp;quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//将原先的html代码放在一个input中，并追加save和cancel按钮后插入到列表li中</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: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;input type=&quot;text&quot; class=&quot;editInput&quot; value=&quot;'</span> <span style="color: #339933;">+</span> oldText <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot; /&gt;&lt;a href=&quot;#&quot; class=&quot;btnSave&quot;&gt;save&lt;/a&gt;&lt;a href=&quot;#&quot; class=&quot;btnCancel&quot;&gt;cancel&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'target'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'_blank'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">//链接在新窗口中打开</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//点击save按钮，将新的值插入在列表li中</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.btnSave'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</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>
		newText <span style="color: #339933;">=</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: #660066;">siblings</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'input'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/&quot;/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;&amp;quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>newText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//设置超链接a的跳转为否</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//若点击cancel按钮，则将最初的html代码插入在列表li中</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.btnCancel'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</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>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>oldText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//设置超链接a的跳转为否</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>双击列表li后，将原先列表li中的html源码保存在oldText变量中，并且在列表li标签内插入一个input输入框和两个链接作为按钮save和cancel之用；<br />
点击save按钮后，将input中的新的html源码保存在newText变量中，重新插入到列表li中，从而覆盖了列表里中的input源码；<br />
点击cancel按钮，浙江原先的html代码oldText重新插入到列表li中，覆盖掉因双击插入的input输入框和两个链接按钮。
</p>
<p class="color-red">注意：源代码中没有jQuery库文件，请下载查看代码的朋友根据源代码路径自行添加。</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2010年11月25日 -- <a href="http://www.ihiro.org/css-position-hack" title="CSS:position属性定位总结">CSS:position属性定位总结</a> (28)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年03月25日 -- <a href="http://www.ihiro.org/the-enhanced-ajax-effect-instructions" title="Ajax:近期博客改版的增强Ajax加载说明">Ajax:近期博客改版的增强Ajax加载说明</a> (43)</li><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年03月8日 -- <a href="http://www.ihiro.org/css3-basic" title="CSS:CSS3基础（附图）">CSS:CSS3基础（附图）</a> (12)</li><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li><li>2010年01月20日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a> (6)</li><li>2009年12月16日 -- <a href="http://www.ihiro.org/jquery-once-through-the-event-delegate-to-bind-a-variety-of-time-in-order-to-reduce-the-event-of-redundancy" title="jQuery:通过事件委派一次绑定多种事件，以减少事件冗余">jQuery:通过事件委派一次绑定多种事件，以减少事件冗余</a> (7)</li><li>2009年12月1日 -- <a href="http://www.ihiro.org/how-to-custom-alias-in-plugins-and-page-code" title="jQuery:如何在页面和插件代码中自定义别名">jQuery:如何在页面和插件代码中自定义别名</a> (5)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/ajax-editing-in-placing/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>XPath:语法及示例，前端学习收集</title>
		<link>http://www.ihiro.org/xpath-syntax-and-example</link>
		<comments>http://www.ihiro.org/xpath-syntax-and-example#comments</comments>
		<pubDate>Mon, 21 Sep 2009 03:33:02 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XPath]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=652</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/09/xpath.gif" alt="xpath" title="xpath" width="100" height="100" class="alignleft wp-image-655" />
<p>昨晚在看《精通Javascript》这本书时，看到XPath的部分内容，觉得学到的不是很多。在之前我就只知道Xpath是Xml相关的，Xpath在xml中的作用就像css中的选择器一样的作用，但具体的语法什么的都没有去关注过。于是今天一早在<a href="http://www.w3school.com.cn/" rel="external">W3C School</a>看收集了一些XPath相关的知识，与大家分享一下！</p>
<p>“XPath 使用路径表达式来选取 XML 文档中的节点或节点集。节点是通过沿着路径 (path) 或者步 (steps) 来选取的。”</p>
<p>更多的XPath资料请访问:<a href="http://www.w3school.com.cn/xpath/index.asp" rel="external">http://www.w3school.com.cn/xpath/index.asp</a></p>]]></description>
			<content:encoded><![CDATA[<p>昨晚在看《精通Javascript》这本书时，看到XPath的部分内容，觉得学到的不是很多。在之前我就只知道Xpath是Xml相关的，Xpath在xml中的作用就像css中的选择器一样的作用，但具体的语法什么的都没有去关注过。于是今天一早在<a href="http://www.w3school.com.cn/" rel="external">W3C School</a>看收集了一些XPath相关的知识，与大家分享一下！</p>
<p>
<blockquote><span>XPath 使用路径表达式来选取 XML 文档中的节点或节点集。节点是通过沿着路径 (path) 或者步 (steps) 来选取的。</span></p></blockquote>
<h3>XML 实例文档</h3>
<p>将在下面的例子中使用这个 XML 文档。</p>

<div class="wp_codebox"><table><tr id="p652152"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code" id="p652code152"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt; ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;ISO-8859-1&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;bookstore<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;eng&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Harry Potter<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>29.99<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;eng&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Learning XML<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>39.95<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/price<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/bookstore<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

</p>
<h3>一、选取节点</h3>
<p>XPath 使用路径表达式在 XML 文档中选取节点。节点是通过沿着路径或者 step 来选取的。<br />
<strong>下面列出了最有用的路径表达式：</strong><br />
<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/09/XPath-01.jpg" alt="XPath-01" title="XPath-01" width="464" height="177" class="aligncenter size-full wp-image-656" /><br />
<strong>实例</strong><br />
在下面的表格中，我们已列出了一些路径表达式以及表达式的结果：<br />
<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/09/XPath-02.jpg" alt="XPath-02" title="XPath-02" width="594" height="218" class="aligncenter size-full wp-image-657" />
</p>
<h3>二、谓语（Predicates）</h3>
<p>谓语用来查找某个特定的节点或者包含某个指定的值的节点。谓语被嵌在方括号中。<br />
<strong>实例</strong><br />
在下面的表格中，我们列出了带有谓语的一些路径表达式，以及表达式的结果：<br />
<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/09/XPath-03.jpg" alt="XPath-03" title="XPath-03" width="589" height="258" class="aligncenter size-full wp-image-658" />
</p>
<h3>三、选取未知节点</h3>
<p>XPath 通配符可用来选取未知的 XML 元素。<br />
<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/09/XPath-04.jpg" alt="XPath-04" title="XPath-04" width="321" height="100" class="aligncenter size-full wp-image-659" /><br />
<strong>实例</strong><br />
在下面的表格中，我们列出了一些路径表达式，以及这些表达式的结果：<br />
<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/09/XPath-05.jpg" alt="XPath-05" title="XPath-05" width="378" height="100" class="aligncenter size-full wp-image-660" /></p>
<h3>四、选取若干路径</h3>
<p>通过在路径表达式中使用“|”运算符，您可以选取若干个路径。<br />
<strong>实例</strong><br />
在下面的表格中，我们列出了一些路径表达式，以及这些表达式的结果：<br />
<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/09/XPath-06.jpg" alt="XPath-06" title="XPath-06" width="568" height="115" class="aligncenter size-full wp-image-661" />
</p>
<h3>五、XPath 轴</h3>
<p>轴可定义某个相对于当前节点的节点集。<br />
<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/09/XPath-07.jpg" alt="XPath-07" title="XPath-07" width="506" height="332" class="aligncenter size-full wp-image-666" />
</p>
<h3>六、位置路径表达式</h3>
<p>位置路径可以是绝对的，也可以是相对的。<br />
绝对路径起始于正斜杠( / )，而相对路径不会这样。在两种情况中，位置路径均包括一个或多个步，每个步均被斜杠分割：</p>
<p>绝对位置路径：/step/step/&#8230;<br />
相对位置路径：step/step/&#8230;<br />
每个步均根据当前节点集之中的节点来进行计算。</p>
<p>步（step）包括：<br />
轴（axis）:    定义所选节点与当前节点之间的树关系<br />
节点测试（node-test）:    识别某个轴内部的节点<br />
零个或者更多谓语（predicate）:    更深入地提炼所选的节点集</p>
<p>步的语法：轴名称::节点测试[谓语]<br />
<strong>实例</strong><br />
<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/09/XPath-08.jpg" alt="XPath-08" title="XPath-08" width="565" height="280" class="aligncenter size-full wp-image-665" />
</p>
<p style="color:#f00">该文来自网络收集，仅供学习之用！更多的XPath资料请访问:<a href="http://www.w3school.com.cn/xpath/index.asp" rel="external">http://www.w3school.com.cn/xpath/index.asp</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2009年07月10日 -- <a href="http://www.ihiro.org/the-effection-of-books-show" title="jQuery:书籍展示效果">jQuery:书籍展示效果</a> (6)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/xpath-syntax-and-example/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Javascript:面向对象之静态、公有、私有、特权对象</title>
		<link>http://www.ihiro.org/javascript-oop</link>
		<comments>http://www.ihiro.org/javascript-oop#comments</comments>
		<pubDate>Thu, 10 Sep 2009 01:39:35 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[Pure Javascript]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=556</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/09/javascript-objects.gif" alt="javascript-objects" title="javascript-objects" class="alignleft size-full wp-image-557" />
<p>虽然我对jQuery库的应用比较熟悉，但对他的内部实现机制还是有许多懵懂之处。于是乎，近日开始学习Javascript面向对象编程。在此学习过程中，会整理一些笔记发布在我的博客上，也提供给和我一样不理解Javascript面向对象编程的朋友一些小小的帮助。</p>
<p>今天就对面向对象编程的几个对象类型做一个实例总结。</p>
<p><strong>1. 静态对象；</strong>&#160;&#160;&#160;&#160;<strong>2. 公有对象；</strong>&#160;&#160;&#160;&#160;<strong>3. 私有对象、特权对象。</strong></p>]]></description>
			<content:encoded><![CDATA[<p>虽然我对jQuery库的应用比较熟悉，但对他的内部实现机制还是有许多懵懂之处。于是乎，近日开始学习Javascript面向对象编程。在此学习过程中，会整理一些笔记发布在我的博客上，也提供给和我一样不理解Javascript面向对象编程的朋友一些小小的帮助。</p>
<p>今天就对面向对象编程的几个对象类型做一个实例总结。</p>
<h3>1. 静态对象</h3>
<p>首先创建一个隐式的Function对象并赋给了myConstructor变量，在创建完对象后，通过添加静态的属性和方法来补充该myConstructor实例化后的对象，代码如下：</p>

<div class="wp_codebox"><table><tr id="p556153"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p556code153"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> myConstructor <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: #006600; font-style: italic;">//some code</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">// -----此处的name属性和alertName方法都属于静态对象</span>
myConstructor.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;hiro&quot;</span><span style="color: #339933;">;</span>
myConstructor.<span style="color: #660066;">alertName</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>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">// -----此处的()起到了执行代码的作用</span>
myConstructor.<span style="color: #660066;">alertName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>2. 公有对象</h3>
<p>创建一个显式的Function对象，然后实例化对象，通过向实例化后的对象中的原型prototype添加属性和方法来产生公有的属性和方法，代码如下：</p>

<div class="wp_codebox"><table><tr id="p556154"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p556code154"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> myConstructor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">//some code</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> myConstructor<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// -----此处通过javascript的原型prototype来添加公有对象</span>
myConstructor.<span style="color: #660066;">prototype</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;hiro&quot;</span><span style="color: #339933;">;</span>
myConstructor.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">alertName</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>
	<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">// -----此处的()起到了执行代码的作用</span>
obj.<span style="color: #660066;">alertName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<h3>3. 私有对象、特权对象</h3>
<p>创建一个显式的Function对象，在该对象内部定义的变量或方法为私有对象，而在该兑现内部通过this.来引用的属性和方法为特权方法，之所以称为“特权”，是因为特权对象可以访问私有对象，代码如下：</p>

<div class="wp_codebox"><table><tr id="p556155"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code" id="p556code155"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span>  myConstructor<span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// -----此处的name和alertName为私有对象，只能在函数对象内部访问</span>
	<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066;">name</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;hiro&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">function</span> alertName<span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><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: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// -----此处的myMessage和alertMessage为特权方法，它既可以被函数对象外部访问，也可以访问函数内部对象的私有对象</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myMessage</span> <span style="color: #339933;">=</span> message<span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">alertMessage</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>
                <span style="color: #006600; font-style: italic;">// -----此处访问了函数对象内部的name和alertName私有对象</span>
		alertName<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ihiro.org&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">myMessage</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;, &quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	alertName<span style="color: #009900;">&#40;</span><span style="color: #000066;">name</span><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> obj <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> myConstructor<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;A object is created&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">myMessage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
obj.<span style="color: #660066;">alertMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</p>
<p>以上语言性描述纯属个人理解，有理解不到位的地方给我提示出来，谢谢！</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li><li>2010年11月22日 -- <a href="http://www.ihiro.org/text-range" title="Range:文本框选区学习笔记">Range:文本框选区学习笔记</a> (16)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2011年02月24日 -- <a href="http://www.ihiro.org/scroll-images" title="Javascript:图片无限循环滚动">Javascript:图片无限循环滚动</a> (27)</li><li>2010年12月30日 -- <a href="http://www.ihiro.org/javascript-getweek-by-date" title="Javascript:根据指定日期获得星期数">Javascript:根据指定日期获得星期数</a> (23)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2010年08月12日 -- <a href="http://www.ihiro.org/sizzle-custom-selector" title="Sizzle:开源JS选择器，如何自定义选择器">Sizzle:开源JS选择器，如何自定义选择器</a> (31)</li><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/javascript-oop/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>CSS:分享一些常用的css技巧</title>
		<link>http://www.ihiro.org/share-some-common-techniques-of-css</link>
		<comments>http://www.ihiro.org/share-some-common-techniques-of-css#comments</comments>
		<pubDate>Thu, 03 Sep 2009 15:05:04 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[CSS、XHTML]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[技巧]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=538</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/09/common-used-css-skills.jpg" alt="common-used-css-skills" title="common-used-css-skills" width="100" height="100" class="alignleft size-full wp-image-542" />
<p>随着近几年来Web标准的流行，css也逐渐有原先辅助的角色转变成了各大网站编程的重要组成部分一直。它很好地将样式与内容分离，使得后期的版面维护与更新工作得以更加地便捷！</p>
<p>今天与大家分享一些在网站开发过程中常用到的一些css技巧，或许会给你的编写带来一些方便之处。已经知晓这些技巧的人完全可以忽略这篇文章。</p>
<p>这些css技巧或许很简单，但我的初衷是希望可以给初学者带去一些帮助。当然css技巧远远不止这些，以后会逐渐整理了发表出来与大家分享。</p>]]></description>
			<content:encoded><![CDATA[<p>随着近几年来Web标准的流行，css也逐渐有原先辅助的角色转变成了各大网站编程的重要组成部分一直。它很好地将样式与内容分离，使得后期的版面维护与更新工作得以更加地便捷！</p>
<p>今天与大家分享一些在网站开发过程中常用到的一些css技巧，或许会给你的css编写带来一些方便之处。已经知晓这些技巧的人完全可以忽略这篇文章。</p>
<h3>1. 使用!important:</h3>
<p>!important是用来将css属性的优先权提升到之高无上的地步，任何多余的装饰在!important的面前都无用无知地。使用方法：</p>

<div class="wp_codebox"><table><tr id="p538156"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p538code156"><pre class="css" style="font-family:monospace;">.<span style="color: #993333;">text</span> <span style="color: #00AA00;">&#123;</span> 
        <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">blue</span> !important<span style="color: #00AA00;">;</span>   //只需在css属性后加上!important即可，与属性间的空格可有可无
        <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #993333;">red</span><span style="color: #00AA00;">;</span>  //尽管该css属性是写在后面，但没有起到任何的作用
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</p>
<h3>2. 使用background设置图片来替换文本：</h3>
<p>每个网站都有一个logo，如果使用a标签直接包含logo图片，这样的做法对搜索引擎不太友好。此时，我们可以用a标签包含一段文字，通过css来的background属性来隐藏文字，同时设置a标签的背景图片为logo图片，这样可以更加友好地优化了网站。</p>

<div class="wp_codebox"><table><tr id="p538157"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p538code157"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.logo</span> a <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">120px</span><span style="color: #00AA00;">;</span>  //此处的宽度和高度与logo图片的宽度和高度一致即可
      <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">80px</span><span style="color: #00AA00;">;</span>  
      <span style="color: #000000; font-weight: bold;">text-indent</span><span style="color: #00AA00;">:</span><span style="color: #933;">-9999px</span><span style="color: #00AA00;">;</span>  
      <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'logo.gif'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span>   
 <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</p>
<h3>3. 清除浮动：</h3>
<p>在网站的布局设置时，经常会出现通过浮动来布局网站内容的分布。但若该元素浮动后，它就脱离了它的父亲的管束，会导致它的父亲的高度为0。为了不是父亲的后面的兄弟们的布局出现问题,此时需要对父亲清除浮动.方法有二:<br />
<br />01. 在父亲的浮动儿子后面插入一个块级元素,如div,设置该div的css为clear,编写css:</p>

<div class="wp_codebox"><table><tr id="p538158"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p538code158"><pre class="css" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">clear</span> <span style="color: #00AA00;">&#123;</span>
       <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>02. 使用overflow和heigth组合的方式,设置父亲father的css为:</p>

<div class="wp_codebox"><table><tr id="p538159"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p538code159"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.father</span> <span style="color: #00AA00;">&#123;</span>
       <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>  //标准浏览器中生效
       <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span>%1<span style="color: #00AA00;">;</span>    //兼容IE6
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</p>
<h3>4. 文字垂直居中</h3>
<p> 若有一个h3包含的标题，你设置了它的高度为30px，就会发现它是居上边显示的，此时你只需结合line-heigth属性即可实现居中效果：</p>

<div class="wp_codebox"><table><tr id="p538160"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p538code160"><pre class="css" style="font-family:monospace;">h3 <span style="color: #00AA00;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
      <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</p>
<h3>5. 网站整体内容居中</h3>
<p>大家都知道有个属性text-align:center;可以是文本居中，该属性在ie6下也可以实现将网站的整体居中显示。但在标准浏览器中，该属性是不起作用的。在标准浏览器中却可以使用margin:0 auto;属性是网站的整体内容居中，但该属性在IE6中却不能识别，所以为了兼容多浏览器，可以组合使用：</p>

<div class="wp_codebox"><table><tr id="p538161"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p538code161"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>    //在body标签中设置该属性给IE6认识只用
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#wrapper</span> <span style="color: #00AA00;">&#123;</span>
       <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>   //在标准浏览器中，先须将文章的内容居左显示
       <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>    //然后使用<span style="color: #000000; font-weight: bold;">margin</span>属性将网站整体内容居中
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</p>
<p>这些css技巧或许很简单，但我的初衷是希望可以给初学者带去一些帮助。当然css技巧远远不止这些，以后会逐渐整理了发表出来与大家分享。</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年03月2日 -- <a href="http://www.ihiro.org/css-specific-for-internet-explorer" title="CSS:区分IE版本的三个方法">CSS:区分IE版本的三个方法</a> (27)</li><li>2010年05月17日 -- <a href="http://www.ihiro.org/target-every-version-of-ie-from-a-single-stylesheet" title="CSS:通过一个样式表区分IE的各个版本">CSS:通过一个样式表区分IE的各个版本</a> (11)</li><li>2010年11月25日 -- <a href="http://www.ihiro.org/css-position-hack" title="CSS:position属性定位总结">CSS:position属性定位总结</a> (28)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年06月12日 -- <a href="http://www.ihiro.org/firefox-4-will-support-css3-calc-method" title="CSS:Firefox 4 将支持CSS3 calc方法">CSS:Firefox 4 将支持CSS3 calc方法</a> (18)</li><li>2010年03月8日 -- <a href="http://www.ihiro.org/css3-basic" title="CSS:CSS3基础（附图）">CSS:CSS3基础（附图）</a> (12)</li><li>2010年02月20日 -- <a href="http://www.ihiro.org/how-to-insert-googlebuzz-data-into-blog" title="Wordpress:如何将GoogleBuzz数据插入到博客中">Wordpress:如何将GoogleBuzz数据插入到博客中</a> (11)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年09月16日 -- <a href="http://www.ihiro.org/including-wordpress-comment-reply-js" title="Wordpress:正确地引入comment-reply.js文件">Wordpress:正确地引入comment-reply.js文件</a> (24)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/share-some-common-techniques-of-css/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>jQuery:热点图片轮换展示效果</title>
		<link>http://www.ihiro.org/jquery-hot-pictures-showing-effects-of-rotation</link>
		<comments>http://www.ihiro.org/jquery-hot-pictures-showing-effects-of-rotation#comments</comments>
		<pubDate>Fri, 28 Aug 2009 08:02:54 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[案例分享]]></category>
		<category><![CDATA[Cases]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=510</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/08/imgPlay.jpg" alt="imgPlay" title="imgPlay" width="100" height="100" class="alignleft size-full wp-image-512" />
<p>分享一个我做的图片轮换展示效果，主要实现原理：通过设置非第一个图片的position，通过overflow:hidden属性隐藏，再使用jQuery的animate效果函数作出链性轮换的效果。</p>
<p>轮换的图片是我第一个主题的banner大图的截图版。在提供下载的压缩包里有一个png的图片是Fireworks的源文件，喜欢修改的朋友可以自行修改！另压缩包中的源码没有添加注释，不懂的请阅读本文中的注释。</p>
<p>PS：jQuery库请根据源码的路径自行加入，压缩包中不提供下载。</p>]]></description>
			<content:encoded><![CDATA[<p>分享一个我做的图片轮换展示效果，主要实现原理：通过设置非第一个图片的position，通过overflow:hidden属性隐藏，再使用jQuery的animate效果函数作出链性轮换的效果。</p>
<p>轮换的图片是我第一个主题的banner大图的截图版。在提供下载的压缩包里有一个png的图片是Fireworks的源文件，喜欢修改的朋友可以自行修改！另压缩包中的源码没有添加注释，不懂的请阅读本文中的注释。</p>
<p>PS：jQuery库请根据源码的路径自行加入，压缩包中不提供下载。</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/imgPlay/imgPlay.rar" class="download" rel="external">download</a><a href="http://www.ihiro.org/cases/imgPlay/" class="demo" rel="external">demo</a></p>
<h3>1.Html代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p510162"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p510code162"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;imgs&quot;&gt;
        &lt;div class=&quot;top&quot;&gt;&lt;/div&gt;
        &lt;div class=&quot;mid&quot;&gt;
            &lt;ul&gt;
                &lt;li class=&quot;first&quot;&gt;&lt;a href=&quot;#&quot;&gt;&lt;img src=&quot;images/1.jpg&quot; alt=&quot;1&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;img src=&quot;images/2.jpg&quot; alt=&quot;2&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;img src=&quot;images/3.jpg&quot; alt=&quot;3&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;&lt;img src=&quot;images/4.jpg&quot; alt=&quot;4&quot; /&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
            &lt;div id=&quot;img_list&quot;&gt;
            	&lt;a href=&quot;#1&quot; class=&quot;active&quot;&gt;1&lt;/a&gt;
            	&lt;a href=&quot;#2&quot;&gt;2&lt;/a&gt;
            	&lt;a href=&quot;#3&quot;&gt;3&lt;/a&gt;
            	&lt;a href=&quot;#4&quot;&gt;4&lt;/a&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;btm&quot;&gt;&lt;/div&gt;
    &lt;/div&gt;</pre></td></tr></table></div>

</p>
<h3>2.Css代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p510163"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p510code163"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#eee</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#imgs</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">500px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
.<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.btm</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/sprite.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
.<span style="color: #000000; font-weight: bold;">top</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.btm</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">-5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">7px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.mid</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">486px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/bg_img.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-y</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span> <span style="color: #933;">7px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.mid</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">486px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">186px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.mid</span> ul li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">486px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">186px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">490px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.mid</span> ul li<span style="color: #6666ff;">.first</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#img_list</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">486px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">1%</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#img_list</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-indent</span><span style="color: #00AA00;">:</span><span style="color: #933;">-9999px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/sprite.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">-13px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#img_list</span> a<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#img_list</span> a<span style="color: #6666ff;">.active</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #933;">-14px</span> <span style="color: #933;">-13px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

</p>
<h3>3.jQuery代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p510164"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
</pre></td><td class="code" id="p510code164"><pre class="js" style="font-family:monospace;">/* start ----- play img*/
var curr = 0, next = 0, count = 0;
$(document).ready(function() {
        // 记录图片的数量	
	count = $('#img_list a').size();	
&nbsp;
	t = setInterval('imgPlay()', 3000);
&nbsp;
        // 鼠标移动到图片或导航上停止播放，移开后恢复播放	
	$('#imgs li, #img_list a').hover(function() {
		clearInterval(t);
	}, function() {
		t = setInterval('imgPlay()', 3000);
	});
&nbsp;
	//点击导航播放到相应的图片		
	$('#img_list a').click(function() {
                // index()函数返回当前导航的下标
		var index = $('#img_list a').index(this);
		if(curr != index) {
			play(index);
			curr = index;
		};
			return false;
		});	
	});
&nbsp;
	// 播放图片的函数
	var imgPlay = function() {
		next = curr + 1;
                // 若当前图片播放到最后一张，这设置下一张要播放的图片为第一张图片的下标
		if(curr == count-1) next=0;
		play(next);
&nbsp;
		curr++;
                // 在当前图片的下标加1后，若值大于最后一张图片的下标，则设置下一轮其实播放的图片下标为第一张图片的下标，而next永远比curr大1
		if(curr &gt; count-1) { curr=0; next = curr +1; }
	};
&nbsp;
	// 控制播放效果的函数
	var play = function(next) {
                // 当前的图片滑到左边-500px，完成后返回到右边490px
                // 下一张图片滑到0px处，完成后导航的焦点切换到下一个点上
		$('#imgs li').eq(curr).css({'opacity': '0.5'}).animate({'left': '-500px', 'opacity': '1'}, 'slow', function() {
				$(this).css({'left': '490px'});
			}).end()
			.eq(next).animate({'left': '0px', 'opacity': '1'}, 'slow', function() {
				$('#img_list a').siblings('a').removeClass('active').end().eq(next).addClass('active');
			});
};
/* endof ----- play img*/</pre></td></tr></table></div>
</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2009年07月14日 -- <a href="http://www.ihiro.org/keyboard-simulation-with-css-and-jquery" title="jQuery:使用css+jQuery模拟键盘">jQuery:使用css+jQuery模拟键盘</a> (10)</li><li>2009年07月10日 -- <a href="http://www.ihiro.org/the-effection-of-books-show" title="jQuery:书籍展示效果">jQuery:书籍展示效果</a> (6)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/the-effection-of-tab-like-msn" title="jQuery:仿MSN网站的tab效果">jQuery:仿MSN网站的tab效果</a> (30)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/a-simple-6-lines-of-code-to-achieve-the-tab-effecttion" title="jQuery：简单6行代码实现tab效果">jQuery：简单6行代码实现tab效果</a> (10)</li><li>2009年06月30日 -- <a href="http://www.ihiro.org/the-effection-of-thunder-home-page" title="jQuery：仿迅雷首页热片滑动效果">jQuery：仿迅雷首页热片滑动效果</a> (6)</li><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年07月6日 -- <a href="http://www.ihiro.org/pure-css-dynamic-page-effects" title="CSS:纯css的伪动态分页效果">CSS:纯css的伪动态分页效果</a> (17)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/jquery-hot-pictures-showing-effects-of-rotation/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>jQuery:Scrolltop滑动插件推荐（修正注释版）</title>
		<link>http://www.ihiro.org/jquery-scrolltop-plugins</link>
		<comments>http://www.ihiro.org/jquery-scrolltop-plugins#comments</comments>
		<pubDate>Fri, 21 Aug 2009 08:51:40 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[插件开发]]></category>
		<category><![CDATA[Plugins]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=470</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/08/scolltotop.jpg" alt="scolltotop" title="scolltotop" width="100" height="100" class="alignleft size-full wp-image-480" />
<p>前段时间<a href="http://cxt5.cn/" rel="external">DeepBlue</a>发邮件问我，博客中的滑动到顶端的效果是如何实现的。我当时忙着做事，就简单地回复他说是用javascript实现的，但没有告诉他具体实现的办法。</p>
<p>今天在使用Google Reader时，在一篇文章里发现了这个插件，很小巧，代码也很易懂。于是乎，添加了中文注释与大家分享一下。</p>
<p>更多英文资料请阅读:<a href="http://www.dynamicdrive.com/dynamicindex3/scrolltop.htm" rel="external">http://www.dynamicdrive.com/dynamicindex3/scrolltop.htm</a></p>]]></description>
			<content:encoded><![CDATA[<p>前段时间<a href="http://cxt5.cn/" rel="external">DeepBlue</a>发邮件问我，博客中的滑动到顶端的效果是如何实现的。我当时忙着做事，就简单地回复他说是用javascript实现的，但没有告诉他具体实现的办法。</p>
<p>今天在使用Google Reader时，在一篇文章里发现了这个插件，很小巧，代码也很易懂。于是乎，添加了中文注释与大家分享一下。（我修复了它的一个bug）先看看效果吧：(下载包里含有插件和一个简单的效果，请自行添加jQuery库)</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/scrolltotop/scrolltotop.rar" class="download">download</a><a href="http://www.ihiro.org/cases/scrolltotop/"  rel="external" class="demo">demo</a></p>
<h3>1.html\css代码：</h3>
<p>
<div class="wp_codebox"><table><tr id="p470165"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code" id="p470code165"><pre class="html" style="font-family:monospace;">&lt; !DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;scroll-to-top&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;../js/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;scrolltopcontrol.js&quot;&gt;&lt;/script&gt;
	&lt;style type=&quot;text/css&quot;&gt;
	* { margin:0; padding:0;}
	body { font:16px;}
&nbsp;
	#wrapper { width:300px; font-size:40px; margin:0 auto; height:1500px;}
&nbsp;
	#topcontrol { padding:10px 20px; background:#F90;}
	&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;wrapper&quot;&gt;top content&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>说明：1.先将js文件引入；<br />
2.我使用一个#wrapper的div将页面撑高；<br />
3.我将通过插件插入的#topcontrol这个div进行简单的css修饰，更加清楚地发现它的位置。</p>
<h3>2.插件javascript代码（含中文注释）：</h3>
<p>
<div class="wp_codebox"><table><tr id="p470166"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
</pre></td><td class="code" id="p470code166"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> scrolltotop<span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">//startline: 鼠标向下滚动了100px后出现#topcontrol</span>
	<span style="color: #006600; font-style: italic;">//scrollto: 它的值可以是整数，也可以是一个id标记。若为整数（假设为n），则滑动到距离top的n像素处；若为id标记，则滑动到该id标记所在的同等高处</span>
	<span style="color: #006600; font-style: italic;">//scrollduration:滑动的速度</span>
	<span style="color: #006600; font-style: italic;">//fadeduration:#topcontrol这个div的淡入淡出速度，第一个参数为淡入速度，第二个参数为淡出速度</span>
	<span style="color: #006600; font-style: italic;">//controlHTML:控制向上滑动的html源码，默认为&lt;img src=&quot;up.png&quot; style=&quot;width:48px; height:48px&quot; /&gt;，可以自行更改。该处的html代码会被包含在一个id标记为#topcontrol的div中。</span>
	<span style="color: #006600; font-style: italic;">//controlattrs:控制#topcontrol这个div距离右下角的像素距离</span>
	<span style="color: #006600; font-style: italic;">//anchorkeyword:滑动到的id标签</span>
	<span style="color: #006600; font-style: italic;">/*state: isvisible:是否#topcontrol这个div为可见
			shouldvisible:是否#topcontrol这个div该出现
	*/</span>
&nbsp;
	setting<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>startline<span style="color: #339933;">:</span><span style="color: #CC0000;">100</span><span style="color: #339933;">,</span> scrollto<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> scrollduration<span style="color: #339933;">:</span><span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> fadeduration<span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">100</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
	controlHTML<span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;a href=&quot;#top&quot;&gt;back-to-top&lt;/a&gt;'</span><span style="color: #339933;">,</span>
	controlattrs<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>offsetx<span style="color: #339933;">:</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> offsety<span style="color: #339933;">:</span><span style="color: #CC0000;">5</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
	anchorkeyword<span style="color: #339933;">:</span> <span style="color: #3366CC;">'#top'</span><span style="color: #339933;">,</span> 
&nbsp;
	state<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>isvisible<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span> shouldvisible<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	scrollup<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><span style="color: #339933;">!</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cssfixedsupport</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.$control.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>opacity<span style="color: #339933;">:</span><span style="color: #CC0000;">0</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: #006600; font-style: italic;">//点击后隐藏#topcontrol这个div</span>
		<span style="color: #003366; font-weight: bold;">var</span> dest<span style="color: #339933;">=</span>isNaN<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setting</span>.<span style="color: #660066;">scrollto</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;">setting</span>.<span style="color: #660066;">scrollto</span> <span style="color: #339933;">:</span> parseInt<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setting</span>.<span style="color: #660066;">scrollto</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> dest<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;string&quot;</span> <span style="color: #339933;">&amp;&amp;</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>dest<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">==</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//检查若scrollto的值是一个id标记的话</span>
			dest<span style="color: #339933;">=</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#'</span><span style="color: #339933;">+</span>dest<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">top</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//检查若scrollto的值是一个整数</span>
			dest<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setting</span>.<span style="color: #660066;">scrollto</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.$body.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>scrollTop<span style="color: #339933;">:</span> dest<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setting</span>.<span style="color: #660066;">scrollduration</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	keepfixed<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: #006600; font-style: italic;">//获得浏览器的窗口对象</span>
		<span style="color: #003366; font-weight: bold;">var</span> $window<span style="color: #339933;">=</span>jQuery<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">//获得#topcontrol这个div的x轴坐标</span>
		<span style="color: #003366; font-weight: bold;">var</span> controlx<span style="color: #339933;">=</span>$window.<span style="color: #660066;">scrollLeft</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> $window.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000066; font-weight: bold;">this</span>.$control.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</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;">controlattrs</span>.<span style="color: #660066;">offsetx</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">//获得#topcontrol这个div的y轴坐标</span>
		<span style="color: #003366; font-weight: bold;">var</span> controly<span style="color: #339933;">=</span>$window.<span style="color: #660066;">scrollTop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> $window.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #000066; font-weight: bold;">this</span>.$control.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</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;">controlattrs</span>.<span style="color: #660066;">offsety</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">//随着滑动块的滑动#topcontrol这个div跟随着滑动</span>
		<span style="color: #000066; font-weight: bold;">this</span>.$control.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>left<span style="color: #339933;">:</span>controlx<span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #339933;">,</span> top<span style="color: #339933;">:</span>controly<span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	togglecontrol<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: #006600; font-style: italic;">//当前窗口的滑动块的高度</span>
		<span style="color: #003366; font-weight: bold;">var</span> scrolltop<span style="color: #339933;">=</span>jQuery<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">scrollTop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">cssfixedsupport</span><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;">keepfixed</span><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: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">//若设置了startline这个参数，则shouldvisible为true</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">state</span>.<span style="color: #660066;">shouldvisible</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>scrolltop<span style="color: #339933;">&gt;=</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setting</span>.<span style="color: #660066;">startline</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">//若shouldvisible为true，且!isvisible为true</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;">state</span>.<span style="color: #660066;">shouldvisible</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">state</span>.<span style="color: #660066;">isvisible</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.$control.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>opacity<span style="color: #339933;">:</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setting</span>.<span style="color: #660066;">fadeduration</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</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;">state</span>.<span style="color: #660066;">isvisible</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">//若shouldvisible为false，且isvisible为false</span>
		<span style="color: #000066; font-weight: bold;">else</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;">state</span>.<span style="color: #660066;">shouldvisible</span><span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">state</span>.<span style="color: #660066;">isvisible</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.$control.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>opacity<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setting</span>.<span style="color: #660066;">fadeduration</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#93;</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;">state</span>.<span style="color: #660066;">isvisible</span><span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	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>
		jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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> mainobj<span style="color: #339933;">=</span>scrolltotop<span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> iebrws<span style="color: #339933;">=</span>document.<span style="color: #660066;">all</span><span style="color: #339933;">;</span>
			mainobj.<span style="color: #660066;">cssfixedsupport</span><span style="color: #339933;">=!</span>iebrws <span style="color: #339933;">||</span> iebrws <span style="color: #339933;">&amp;&amp;</span> document.<span style="color: #660066;">compatMode</span><span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;CSS1Compat&quot;</span> <span style="color: #339933;">&amp;&amp;</span> window.<span style="color: #660066;">XMLHttpRequest</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//not IE or IE7+ browsers in standards mode</span>
			mainobj.$body<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">opera</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">compatMode</span><span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;CSS1Compat&quot;</span><span style="color: #339933;">?</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'html,body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">//包含#topcontrol这个div</span>
			mainobj.$control<span style="color: #339933;">=</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;div id=&quot;topcontrol&quot;&gt;'</span><span style="color: #339933;">+</span>mainobj.<span style="color: #660066;">controlHTML</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'&lt;/div&gt;'</span><span style="color: #009900;">&#41;</span>
				.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>position<span style="color: #339933;">:</span>mainobj.<span style="color: #660066;">cssfixedsupport</span><span style="color: #339933;">?</span> <span style="color: #3366CC;">'fixed'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'absolute'</span><span style="color: #339933;">,</span> bottom<span style="color: #339933;">:</span>mainobj.<span style="color: #660066;">controlattrs</span>.<span style="color: #660066;">offsety</span><span style="color: #339933;">,</span> right<span style="color: #339933;">:</span>mainobj.<span style="color: #660066;">controlattrs</span>.<span style="color: #660066;">offsetx</span><span style="color: #339933;">,</span> opacity<span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> cursor<span style="color: #339933;">:</span><span style="color: #3366CC;">'pointer'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
				.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>title<span style="color: #339933;">:</span><span style="color: #3366CC;">'Scroll Back to Top'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
				.<span style="color: #660066;">click</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>mainobj.<span style="color: #660066;">scrollup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
				.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">all</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>window.<span style="color: #660066;">XMLHttpRequest</span> <span style="color: #339933;">&amp;&amp;</span> mainobj.$control.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">//loose check for IE6 and below, plus whether control contains any text</span>
				mainobj.$control.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>width<span style="color: #339933;">:</span>mainobj.$control.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//IE6- seems to require an explicit width on a DIV containing text</span>
			<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
			mainobj.<span style="color: #660066;">togglecontrol</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">//点击控制</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a[href=&quot;'</span> <span style="color: #339933;">+</span> mainobj.<span style="color: #660066;">anchorkeyword</span> <span style="color: #339933;">+</span><span style="color: #3366CC;">'&quot;]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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>
				mainobj.<span style="color: #660066;">scrollup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'scroll resize'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				mainobj.<span style="color: #660066;">togglecontrol</span><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;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</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>
&nbsp;
scrolltotop.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>说明：1.修复代码28行的”dest=this.setting.scrollto“;，源代码为“dest=0”；<br />
2.无须在原html代码中添加#top的标记，js会自动插入；<br />
3.可以修改顶端代码的一些参数来控制滑动速度和其他的一些效果。
</p>
<p>更多英文资料请阅读:<a href="http://www.dynamicdrive.com/dynamicindex3/scrolltop.htm" rel="external">http://www.dynamicdrive.com/dynamicindex3/scrolltop.htm</a></p>
<p>原始的插件代码下载地址(右键另存即可)：<a href="http://www.dynamicdrive.com/dynamicindex3/scrolltopcontrol.js">scrolltopcontrol.js</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年10月21日 -- <a href="http://www.ihiro.org/jquery-plugin-recommended-maphighlight" title="jQuery:热区高亮maphighlight插件推荐">jQuery:热区高亮maphighlight插件推荐</a> (23)</li><li>2010年06月30日 -- <a href="http://www.ihiro.org/firebug-console-panel-function" title="Firebug:Javascript测试利器，Console面板函数详解">Firebug:Javascript测试利器，Console面板函数详解</a> (4)</li><li>2010年02月24日 -- <a href="http://www.ihiro.org/javascript-news-flash-header-tips" title="Javascript:新消息闪烁标题提示代码分享">Javascript:新消息闪烁标题提示代码分享</a> (7)</li><li>2009年11月2日 -- <a href="http://www.ihiro.org/my-first-plugin-scrolltop" title="插件:我的第一个插件&#8211;简约的scrollTop滑动插件">插件:我的第一个插件&#8211;简约的scrollTop滑动插件</a> (23)</li><li>2009年06月18日 -- <a href="http://www.ihiro.org/jquery-plugins-for-dw4" title="jQuery plugins for DW4">jQuery plugins for DW4</a> (2)</li><li>2011年11月25日 -- <a href="http://www.ihiro.org/firebug-extension-firequery" title="插件：Firebug扩展插件FireQuery">插件：Firebug扩展插件FireQuery</a> (2)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年08月12日 -- <a href="http://www.ihiro.org/sizzle-custom-selector" title="Sizzle:开源JS选择器，如何自定义选择器">Sizzle:开源JS选择器，如何自定义选择器</a> (31)</li><li>2010年05月21日 -- <a href="http://www.ihiro.org/dw-html5-extension" title="扩展:Adobe放出Dreamweaver CS5 HTML 5扩展包">扩展:Adobe放出Dreamweaver CS5 HTML 5扩展包</a> (16)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/jquery-scrolltop-plugins/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>jQuery:暴强，两款jQuery的打字游戏推荐</title>
		<link>http://www.ihiro.org/two-jquery-typing-games-recommended</link>
		<comments>http://www.ihiro.org/two-jquery-typing-games-recommended#comments</comments>
		<pubDate>Mon, 17 Aug 2009 02:45:28 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[前端工程]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[游戏]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=440</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/08/jQuery-game.jpg" alt="jQuery-game" title="jQuery-game" width="100" height="100" class="alignleft wp-image-441" />
<p>今日在网上发现两款比较好玩的打字游戏，是运用jQuery库编写的，游戏非常美观，适合打字练习或者休闲一下子。</p>
<p><strong>1. jtypinghero：</strong>你可以修改js文件夹下的script.js文件的一些参数来设置游戏，如DROPPINGSPEED设置下落的速度，NEWORBTIME设置距离下个字母出现的时间等。</p>
<p><strong>2. jcharacterfall：</strong>jcharacterfall是一个小巧的打字游戏，它的字母是随着水滴下落的，下落速度会逐渐地加快。</p>]]></description>
			<content:encoded><![CDATA[<p>今日在网上发现两款比较好玩的打字游戏，是运用jQuery库编写的，游戏非常美观，适合打字练习或者休闲一下子。</p>
<h3>1. jtypinghero</h3>
<p><img src="http://www.ihiro.org/downloads/jtypinghero/jtypinghero.jpg" alt="jtypinghero" class="aligncenter" /><br />
你可以修改js文件夹下的script.js文件的一些参数来设置游戏，如DROPPINGSPEED设置下落的速度，NEWORBTIME设置距离下个字母出现的时间等。</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/downloads/jtypinghero/jtypinghero.zip" title="downloadjtypinghero" class="download">download</a><a href="http://www.ihiro.org/downloads/jtypinghero/" title="play jtypinghero" class="demo">play</a></p>
<h3>2. jcharacterfall</h3>
<p>
<img src="http://www.ihiro.org/downloads/jcharacterfall/jcharacterfall.jpg" alt="jcharacterfall" class="aligncenter" /><br />
jcharacterfall是一个小巧的打字游戏，它的字母是随着水滴下落的，下落速度会逐渐地加快。</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/downloads/jcharacterfall/jcharacterfall.zip" title="download jcharacterfall" class="download">download</a><a href="http://www.ihiro.org/downloads/jcharacterfall/" title="play jcharacterfall" class="demo">play</a></p>
<p>希望玩的开心！</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年10月21日 -- <a href="http://www.ihiro.org/jquery-plugin-recommended-maphighlight" title="jQuery:热区高亮maphighlight插件推荐">jQuery:热区高亮maphighlight插件推荐</a> (23)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年08月12日 -- <a href="http://www.ihiro.org/sizzle-custom-selector" title="Sizzle:开源JS选择器，如何自定义选择器">Sizzle:开源JS选择器，如何自定义选择器</a> (31)</li><li>2010年06月30日 -- <a href="http://www.ihiro.org/firebug-console-panel-function" title="Firebug:Javascript测试利器，Console面板函数详解">Firebug:Javascript测试利器，Console面板函数详解</a> (4)</li><li>2010年03月25日 -- <a href="http://www.ihiro.org/the-enhanced-ajax-effect-instructions" title="Ajax:近期博客改版的增强Ajax加载说明">Ajax:近期博客改版的增强Ajax加载说明</a> (43)</li><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li><li>2010年02月24日 -- <a href="http://www.ihiro.org/javascript-news-flash-header-tips" title="Javascript:新消息闪烁标题提示代码分享">Javascript:新消息闪烁标题提示代码分享</a> (7)</li><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/two-jquery-typing-games-recommended/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>正则:8个你必须知道的表达式（图文教程）</title>
		<link>http://www.ihiro.org/eight-regular-expressions</link>
		<comments>http://www.ihiro.org/eight-regular-expressions#comments</comments>
		<pubDate>Tue, 11 Aug 2009 02:14:59 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[正则表达式]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=409</guid>
		<description><![CDATA[<img src="http://nettuts.s3.amazonaws.com/404_regularExpressions/images/200x200.jpg" class="alignleft" width="100" height="100' alt="reg" />
<p><strong>正则表达式（英文：Regular Expression）</strong>:在计算机科学中，是指一个用来描述或者匹配一系列符合某个句法规则的字符串的单个字符串。在很多文本编辑器或其他工具里，正则表达式通常被用来检索和/或替换那些符合某个模式的文本内容。许多程序设计语言都支持利用正则表达式进行字符串操作。例如，在Perl中就内建了一个功能强大的正则表达式引擎。正则表达式这个概念最初是由Unix中的工具软件（例如sed和grep）普及开的。“正则表达式”通常缩写成“regex”，单数有regexp、regex，复数有regexps、regexes、regexen。</p>
<p>今天我说到的8个正则表达式将会用来匹配:用户名、密码、邮件地址、16进制表达式（如：#cccccc）、slug地址（如：eight-regular-expressions）、URL地址、Ip地址以及HTML标签。在下面的讲解中会结合图片给大家讲解，这样你会更容易地理解这些表达式。</p>]]></description>
			<content:encoded><![CDATA[<p><img src="http://nettuts.s3.amazonaws.com/404_regularExpressions/images/200x200.jpg" class="alignright" width="150" height="150' alt="reg" /></p>
<h3>正则表达式的背景：</h3>
<p>维基百科中这么说到：<br />
<strong>正则表达式（英文：Regular Expression）</strong>:在计算机科学中，是指一个用来描述或者匹配一系列符合某个句法规则的字符串的单个字符串。在很多文本编辑器或其他工具里，正则表达式通常被用来检索和/或替换那些符合某个模式的文本内容。许多程序设计语言都支持利用正则表达式进行字符串操作。例如，在Perl中就内建了一个功能强大的正则表达式引擎。正则表达式这个概念最初是由Unix中的工具软件（例如sed和grep）普及开的。“正则表达式”通常缩写成“regex”，单数有regexp、regex，复数有regexps、regexes、regexen。</p>
<p>今天我说到的8个正则表达式将会用来匹配:用户名、密码、邮件地址、16进制表达式（如：#cccccc）、slug地址（如：eight-regular-expressions）、URL地址、Ip地址以及HTML标签。在下面的讲解中会结合图片给大家讲解，这样你会更容易地理解这些表达式。</p>
<h3>1.匹配英文用户名：</h3>
<p><img src="http://nettuts.s3.amazonaws.com/404_regularExpressions/images/username.jpg" alt="username" width="600" height="370" class="aligncenter" /></p>
<p>表达式：/^[a-z0-9_-]{3,16}$/</p>
<p>可以匹配的字符串：my-us3r_n4m3</p>
<p>不能匹配的字符串：th1s1s-wayt00_l0ngt0beausername (太长了！)</p>
<h3>2.匹配密码：</h3>
<p><img src="http://nettuts.s3.amazonaws.com/404_regularExpressions/images/password.jpg" alt="password" width="600" height="370" class="aligncenter" /></p>
<p>表达式：/^[a-z0-9_-]{6,18}$/</p>
<p>可以匹配的字符串：myp4ssw0rd</p>
<p>不能匹配的字符串：mypa$$w0rd(包含了一个美元符号！)</p>
<h3>3.匹配16进制表达式：</h3>
<p><img src="http://nettuts.s3.amazonaws.com/404_regularExpressions/images/hex-copy.jpg" alt="hex" width="600" height="370" class="aligncenter" /></p>
<p>表达式：/^#?([a-f0-9]{6}|[a-f0-9]{3})$/</p>
<p>可以匹配的字符串：#a3c113</p>
<p>不能匹配的字符串：#4d82h4 (包含了字母h，字母h不属于16进制的字符！)</p>
<h3>4.匹配slug地址：</h3>
<p><img src="http://nettuts.s3.amazonaws.com/404_regularExpressions/images/slug.jpg" alt="slug" width="600" height="370" class="aligncenter" /></p>
<p>表达式：/^[a-z0-9-]+$/ </p>
<p>可以匹配的字符串：eight-regular-expressions</p>
<p>不能匹配的字符串：eight_regular_expressions(包含了下划线！)</p>
<h3>5.匹配邮箱地址：</h3>
<p><img src="http://nettuts.s3.amazonaws.com/404_regularExpressions/images/email.jpg" alt="email" width="600" height="500" class="aligncenter" /></p>
<p>表达式：/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/ </p>
<p>可以匹配的字符串：hiro.zhd@gmail.com</p>
<p>不能匹配的字符串：hiro.zhd@gmail.something(域名的后缀过长！)</p>
<h3>6.匹配URL地址：</h3>
<p><img src="http://nettuts.s3.amazonaws.com/404_regularExpressions/images/url.jpg" alt="url" width="600" height="500" class="aligncenter" /></p>
<p>表达式：/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ </p>
<p>可以匹配的字符串：http://www.ihiro.org/</p>
<p>不能匹配的字符串：http://www.ihiro.org/about!.html(包含了特殊字符“！”！)</p>
<h3>7.匹配IP地址：</h3>
<p><img src="http://nettuts.s3.amazonaws.com/404_regularExpressions/images/ip.jpg" alt="ip" width="600" height="500" class="aligncenter" /></p>
<p>表达式：/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/ </p>
<p>可以匹配的字符串：73.60.124.136(这不是我的ip哦，请不要试图访问，呵呵！)</p>
<p>不能匹配的字符串：256.60.124.136(超过255了！)</p>
<h3>8.匹配HTML标签：</h3>
<p><img src="http://nettuts.s3.amazonaws.com/404_regularExpressions/images/htmltag.jpg" alt="htmltag" width="600" height="500" class="aligncenter" /></p>
<p>表达式：/^< ([a-z]+)([^<]+)*(?:>(.*)< \/\1>|\s+\/>)$/ </p>
<p>可以匹配的字符串：&lt;a href=”http://www.ihiro.org/”&gt;Nettuts+&lt;/a&gt;</p>
<p>不能匹配的字符串：&lt;a href=”http://www.ihiro.org/” title=”Hiro&#8217;s blog &gt;”&gt;Nettuts+&lt;/a&gt;(标签属性包含了特殊字符！)</p>
<p><strong>文章内容整理来自：<a href="http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/" rel="external">http://net.tutsplus.com/tutorials/other/8-regular-expressions-you-should-know/</a></strong></p>
<h2  class="related_post_title">最热评论文章列表:</h2><ul class="related_post"><li>2009年08月5日 -- <a href="http://www.ihiro.org/my-first-theme-for-download" title="主题：我的第一个主题ihiro提供下载了">主题：我的第一个主题ihiro提供下载了</a> (101)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2009年12月31日 -- <a href="http://www.ihiro.org/plugins-garden" title="插件专区">插件专区</a> (50)</li><li>2011年01月11日 -- <a href="http://www.ihiro.org/intellij-idea" title="软件:使用IntelliJ IDEA，高效前端开发">软件:使用IntelliJ IDEA，高效前端开发</a> (50)</li><li>2009年08月7日 -- <a href="http://www.ihiro.org/abandon-google-and-baidu-then-alimama" title="网赚:抛弃谷歌、百度，转战阿里妈妈">网赚:抛弃谷歌、百度，转战阿里妈妈</a> (47)</li><li>2010年03月25日 -- <a href="http://www.ihiro.org/the-enhanced-ajax-effect-instructions" title="Ajax:近期博客改版的增强Ajax加载说明">Ajax:近期博客改版的增强Ajax加载说明</a> (43)</li><li>2009年09月6日 -- <a href="http://www.ihiro.org/highlight-the-administrators-reply-message" title="Wordpress:高亮管理员的留言信息">Wordpress:高亮管理员的留言信息</a> (37)</li><li>2010年08月12日 -- <a href="http://www.ihiro.org/sizzle-custom-selector" title="Sizzle:开源JS选择器，如何自定义选择器">Sizzle:开源JS选择器，如何自定义选择器</a> (31)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/the-effection-of-tab-like-msn" title="jQuery:仿MSN网站的tab效果">jQuery:仿MSN网站的tab效果</a> (30)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/eight-regular-expressions/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>jQuery:两个样式下拉菜单(click hover)</title>
		<link>http://www.ihiro.org/drop-down-menu</link>
		<comments>http://www.ihiro.org/drop-down-menu#comments</comments>
		<pubDate>Thu, 06 Aug 2009 06:51:18 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[案例分享]]></category>
		<category><![CDATA[前端工程]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=367</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/08/dropdownmenu.jpg" alt="dropdownmenu" title="dropdownmenu" width="100" height="90" class="alignleft  wp-image-368" />
<p>一直都很喜欢下拉菜单，因为这样可以导航到更多的页面，给访问者一目了然的感觉。</p>
<p>之前在公司的网站上就是用的下拉菜单导航栏的方式进行导航，当时是使用了li:hover的方式通过鼠标移动到li上，显示出li下的ul。而在ie6中则使用javascript修复li:hover。这样做出来是没有动态的效果，下拉菜单一下子就凭空出现了。</p>
<p>运用jQuery库制作下拉菜单的好处就是可以做出各种不同的动态效果，我今天讲解的是运用slideDown()和slideUp()函数实现的卷页效果。</p>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.ihiro.org/blog/wp-content/uploads/2009/08/dropdownmenu.jpg" alt="dropdownmenu" title="dropdownmenu" width="150" height="133" class="alignright size-full wp-image-368" /></p>
<p>一直都很喜欢下拉菜单，因为这样可以导航到更多的页面，给访问者一目了然的感觉。</p>
<p>之前在公司的网站上就是用的下拉菜单导航栏的方式进行导航，当时是使用了li:hover的方式通过鼠标移动到li上，显示出li下的ul。而在ie6中则使用javascript修复li:hover。这样做出来是没有动态的效果，下拉菜单一下子就凭空出现了。</p>
<p>运用jQuery库制作下拉菜单的好处就是可以做出各种不同的动态效果，我今天讲解的是运用slideDown()和slideUp()函数实现的卷页效果。</p>
<p>说明：第一个导航#nav1是点击后出现下拉菜单，而第二个导航#nav2是鼠标移动到上面后出现导航。(样式只为效果，没有美化，望见谅)</p>
<p class="demo-down-bar"><a href="http://www.ihiro.org/cases/DropDownMenu/DropDownMenu.rar" class="download" rel="external">Download</a><a href="http://www.ihiro.org/cases/DropDownMenu/" class="demo" rel="external">Demo</a></p>
<h3>1.html代码：</h3>

<div class="wp_codebox"><table><tr id="p367167"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code" id="p367code167"><pre class="html" style="font-family:monospace;">&lt;ul class=&quot;nav&quot; id=&quot;nav1&quot;&gt;
    	&lt;li&gt;点击方式下拉菜单:click&lt;/li&gt;
    	&lt;li&gt;&lt;a href=&quot;#&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;关于&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;技术&lt;/a&gt;
        	&lt;ul class=&quot;subnav&quot;&gt;
            	&lt;li&gt;&lt;a href=&quot;#&quot;&gt;wordpress&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;php&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;jQuery&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;CSS&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;影视&lt;/a&gt;
        	&lt;ul class=&quot;subnav&quot;&gt;
            	&lt;li&gt;&lt;a href=&quot;#&quot;&gt;电视剧&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;电影&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;舞台剧&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;联系&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
&nbsp;
    &lt;ul class=&quot;nav&quot; id=&quot;nav2&quot;&gt;
    	&lt;li&gt;移动方式下拉菜单:hover&lt;/li&gt;
    	&lt;li&gt;&lt;a href=&quot;#&quot;&gt;首页&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;关于&lt;/a&gt;&lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;技术&lt;/a&gt;
        	&lt;ul class=&quot;subnav&quot;&gt;
            	&lt;li&gt;&lt;a href=&quot;#&quot;&gt;wordpress&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;php&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;jQuery&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;CSS&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;影视&lt;/a&gt;
        	&lt;ul class=&quot;subnav&quot;&gt;
            	&lt;li&gt;&lt;a href=&quot;#&quot;&gt;电视剧&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;电影&lt;/a&gt;&lt;/li&gt;
                &lt;li&gt;&lt;a href=&quot;#&quot;&gt;舞台剧&lt;/a&gt;&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;#&quot;&gt;联系&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;</pre></td></tr></table></div>

<h3>2. CSS源码：</h3>

<div class="wp_codebox"><table><tr id="p367168"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code" id="p367code168"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span> <span style="color: #ff0000;">'宋体'</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">underline</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#nav1</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.nav</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">500px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#333</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F60</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.nav</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.nav</span> li a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.nav</span> li span <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">17px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">subnav_btn.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.nav</span> li span<span style="color: #6666ff;">.subhover</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
ul<span style="color: #6666ff;">.subnav</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-20px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#666</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
ul<span style="color: #6666ff;">.subnav</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>3. jQuery代码：</h3>

<div class="wp_codebox"><table><tr id="p367169"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code" id="p367code169"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;span&gt;&lt;/span&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">insertBefore</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.subnav'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//鼠标点击向下箭头</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#nav1 li span'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'subhover'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</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: #009900;">&#125;</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>
			$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul.subnav'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</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: #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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'subhover'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul.subnav'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// 鼠标移动到含有下拉菜单的li标签上时</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#nav2 li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'subhover'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
			   .<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul.subnav'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideDown</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slow'</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: #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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'subhover'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
			   .<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul.subnav'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideUp</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li><li>2010年01月20日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a> (6)</li><li>2009年12月16日 -- <a href="http://www.ihiro.org/jquery-once-through-the-event-delegate-to-bind-a-variety-of-time-in-order-to-reduce-the-event-of-redundancy" title="jQuery:通过事件委派一次绑定多种事件，以减少事件冗余">jQuery:通过事件委派一次绑定多种事件，以减少事件冗余</a> (7)</li><li>2009年12月1日 -- <a href="http://www.ihiro.org/how-to-custom-alias-in-plugins-and-page-code" title="jQuery:如何在页面和插件代码中自定义别名">jQuery:如何在页面和插件代码中自定义别名</a> (5)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/drop-down-menu/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>jQuery:使用css+jQuery模拟键盘</title>
		<link>http://www.ihiro.org/keyboard-simulation-with-css-and-jquery</link>
		<comments>http://www.ihiro.org/keyboard-simulation-with-css-and-jquery#comments</comments>
		<pubDate>Tue, 14 Jul 2009 04:56:57 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[案例分享]]></category>
		<category><![CDATA[Cases]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[学习笔记]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=189</guid>
		<description><![CDATA[<p>今天在阅读<a href="http://net.tutsplus.com/" rel="external">Nettuts+</a>的Feed时看到了这个模拟键盘的效果，很是喜欢。便查看的源码后，了解了实现的原理，自己重新编写了CSS和JS代码，现效果如下：</p><p>
<iframe src="http://www.ihiro.org/cases/keyboard/" width="460" height="290"></iframe>
</p><p>外部链接查看效果：<a href="http://www.ihiro.org/cases/keyboard/"  rel="external">Demo</a>,源代码下载：<a href="http://www.ihiro.org/cases/keyboard/keyboard.rar"  rel="external">Download</a></p>]]></description>
			<content:encoded><![CDATA[<p>今天在阅读<a href="http://net.tutsplus.com/" rel="external">Nettuts+</a>的Feed时看到了这个模拟键盘的效果，很是喜欢。便查看的源码后，了解了实现的原理，自己重新编写了CSS和JS代码，现效果如下：</p>
<p>
<iframe src="http://www.ihiro.org/cases/keyboard/" width="460" height="290"></iframe>
</p>
<p>外部链接查看效果：<a href="http://www.ihiro.org/cases/keyboard/"  rel="external">Demo</a>,源代码下载：<a href="http://www.ihiro.org/cases/keyboard/keyboard.rar"  rel="external">Download</a></p>
<h3>1.html代码</h3>

<div class="wp_codebox"><table><tr id="p189170"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code" id="p189code170"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;container&quot;&gt;
	&lt;textarea id=&quot;write&quot; rows=&quot;6&quot; cols=&quot;60&quot;&gt;&lt;/textarea&gt;
	&lt;ul id=&quot;keyboard&quot;&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;~&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;!&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;@&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;#&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;$&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;%&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;^&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;&amp;amp;&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;*&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;(&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;)&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;_&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;+&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;delete lastitem&quot;&gt;delete&lt;/li&gt;
		&lt;li class=&quot;tab&quot;&gt;tab&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;q&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;w&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;e&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;r&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;t&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;y&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;u&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;i&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;o&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;p&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;{&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;}&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol lastitem&quot;&gt;&lt;span class=&quot;off&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;|&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;capslock&quot;&gt;caps lock&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;a&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;s&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;d&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;f&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;g&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;h&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;j&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;k&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;l&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;;&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;:&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;enter lastitem&quot;&gt;enter&lt;/li&gt;
		&lt;li class=&quot;left-shift&quot;&gt;shift&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;z&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;x&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;c&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;v&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;b&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;n&lt;/li&gt;
		&lt;li class=&quot;letter&quot;&gt;m&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;&lt; &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;&gt;&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;symbol&quot;&gt;&lt;span class=&quot;off&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;on&quot;&gt;?&lt;/span&gt;&lt;/li&gt;
		&lt;li class=&quot;right-shift lastitem&quot;&gt;shift&lt;/li&gt;
		&lt;li class=&quot;space lastitem&quot;&gt;space&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<h3>2. CSS代码：</h3>

<div class="wp_codebox"><table><tr id="p189171"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code" id="p189code171"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span> Tahoma<span style="color: #00AA00;">,</span> Geneva<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#eee</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#container</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">430px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #cc00cc;">#write</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">410px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">120px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> -moz-border-radius<span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> -webkit-border-radius<span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#f9f9f9</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">11px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
		<span style="color: #cc00cc;">#keyboard</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #cc00cc;">#keyboard</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> -moz-border-radius<span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> -webkit-border-radius<span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#f9f9f9</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
			<span style="color: #6666ff;">.tab</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.capslock</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.left-shift</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.space</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
			<span style="color: #cc00cc;">#keyboard</span> li<span style="color: #6666ff;">.lastitem</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #cc00cc;">#keyboard</span> li<span style="color: #6666ff;">.delete</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">70px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #cc00cc;">#keyboard</span> li<span style="color: #6666ff;">.tab</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">70px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #cc00cc;">#keyboard</span> li<span style="color: #6666ff;">.capslock</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">75px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #cc00cc;">#keyboard</span> li<span style="color: #6666ff;">.enter</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #cc00cc;">#keyboard</span> li<span style="color: #6666ff;">.left-shift</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">80px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #cc00cc;">#keyboard</span> li<span style="color: #6666ff;">.right-shift</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">65px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #cc00cc;">#keyboard</span> li<span style="color: #6666ff;">.space</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">420px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
			<span style="color: #cc00cc;">#keyboard</span> li<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.hover</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span><span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#e5e5e5</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
			<span style="color: #6666ff;">.on</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			.<span style="color: #993333;">uppercase</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-transform</span><span style="color: #00AA00;">:</span><span style="color: #993333;">uppercase</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>为了兼容IE6和IE7，需在head标签对间加上如下代码：</p>

<div class="wp_codebox"><table><tr id="p189172"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p189code172"><pre class="html" style="font-family:monospace;">&lt;!--[if lt ie 8]&gt;
    &lt;style type=&quot;text/css&quot;&gt;
    	#write { margin-left:-10px;}
    &lt;/style&gt;
&lt; ![endif]--&gt;</pre></td></tr></table></div>

<h3>3. JS代码：</h3>

<div class="wp_codebox"><table><tr id="p189173"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code" id="p189code173"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> $writeBox <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#write'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		shift <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
		capslock <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#keyboard li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hover'</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: #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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hover'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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> $this <span style="color: #339933;">=</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: #339933;">,</span>
			charater <span style="color: #339933;">=</span> $this.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// 一键两意</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'symbol'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> charater <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span:visible'</span><span style="color: #339933;">,</span> $this<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Button detele </span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'delete'</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> html <span style="color: #339933;">=</span> $writeBox.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$writeBox.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>html.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> html.<span style="color: #660066;">length</span><span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Button tab</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tab'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> charater <span style="color: #339933;">=</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\t</span>'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Button capslock</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'capslock'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.letter'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggleClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'uppercase'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			capslock <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Button enter</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'enter'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> charater <span style="color: #339933;">=</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Button shift</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'left-shift'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> $this.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'right-shift'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.letter'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggleClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'uppercase'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.symbol span'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			shift <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>shift <span style="color: #339933;">===</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			capslock <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Button space</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'space'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> charater <span style="color: #339933;">=</span> <span style="color: #3366CC;">' '</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// 转换为大写</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$this.<span style="color: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'uppercase'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> charater <span style="color: #339933;">=</span> charater.<span style="color: #660066;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// 输出所按的键值</span>
		$writeBox.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>$writeBox.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> charater<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>此效果由：<a href="http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-keyboard-with-css-and-jquery/" rel="extrenal">http://net.tutsplus.com/tutorials/javascript-ajax/creating-a-keyboard-with-css-and-jquery/</a>中的效果改编而来。</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2009年08月28日 -- <a href="http://www.ihiro.org/jquery-hot-pictures-showing-effects-of-rotation" title="jQuery:热点图片轮换展示效果">jQuery:热点图片轮换展示效果</a> (14)</li><li>2009年07月10日 -- <a href="http://www.ihiro.org/the-effection-of-books-show" title="jQuery:书籍展示效果">jQuery:书籍展示效果</a> (6)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/the-effection-of-tab-like-msn" title="jQuery:仿MSN网站的tab效果">jQuery:仿MSN网站的tab效果</a> (30)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/a-simple-6-lines-of-code-to-achieve-the-tab-effecttion" title="jQuery：简单6行代码实现tab效果">jQuery：简单6行代码实现tab效果</a> (10)</li><li>2009年06月30日 -- <a href="http://www.ihiro.org/the-effection-of-thunder-home-page" title="jQuery：仿迅雷首页热片滑动效果">jQuery：仿迅雷首页热片滑动效果</a> (6)</li><li>2010年08月12日 -- <a href="http://www.ihiro.org/sizzle-custom-selector" title="Sizzle:开源JS选择器，如何自定义选择器">Sizzle:开源JS选择器，如何自定义选择器</a> (31)</li><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/keyboard-simulation-with-css-and-jquery/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>jQuery:书籍展示效果</title>
		<link>http://www.ihiro.org/the-effection-of-books-show</link>
		<comments>http://www.ihiro.org/the-effection-of-books-show#comments</comments>
		<pubDate>Fri, 10 Jul 2009 03:52:23 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[案例分享]]></category>
		<category><![CDATA[Cases]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=177</guid>
		<description><![CDATA[<p>前段时间在国外的博客上看到这个jQuery的书籍展示效果，觉得很是不错，并下载了源码，自己重新编写了CSS和JS，效果:如下</p>
<iframe src="http://www.ihiro.org/cases/bookShow/" width="520px" height="210"></iframe>
<p>说明：因为在此页面中是通过使用iframe标签引入外部页面，加上显示页面的宽度有限，所以当鼠标移动到Info图标上时，部分内容被遮盖住，这时你可以通过外部链接查看：<a href="http://www.ihiro.org/cases/bookShow/" rel="external">Demo</a></p>
<p><a href="http://www.ihiro.org/cases/bookShow/bookShow.rar" rel="external">源代码下载</a></p>]]></description>
			<content:encoded><![CDATA[<p>前段时间在国外的博客上看到这个jQuery的书籍展示效果，觉得很是不错，并下载了源码，自己重新编写了CSS和JS，效果:如下</p>
<p><iframe src="http://www.ihiro.org/cases/bookShow/" width="520" height="210"></iframe></p>
<p>说明：因为在此页面中是通过使用iframe标签引入外部页面，加上显示页面的宽度有限，所以当鼠标移动到Info图标上时，部分内容被遮盖住，这时你可以通过外部链接查看：<a href="http://www.ihiro.org/cases/bookShow/" rel="external" >Demo</a></p>
<p>具体代码实现如下：（<a href="http://www.ihiro.org/cases/bookShow/bookShow.rar" rel="external">源代码下载</a>）</p>
<h3>1.html代码:</h3>

<div class="wp_codebox"><table><tr id="p177174"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code" id="p177code174"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;books&quot;&gt;
  &lt;div class=&quot;overclear buttons&quot;&gt; 
    &lt;a href=&quot;#&quot; class=&quot;prev&quot;&gt;&lt;img src=&quot;images/books_prev.gif&quot; alt=&quot;Previous&quot; /&gt;&lt;/a&gt;
    &lt;div class=&quot;showing&quot;&gt;&lt;!-- showing --&gt;&lt;/div&gt;
    &lt;a href=&quot;#&quot; class=&quot;next&quot;&gt;&lt;img src=&quot;images/books_next.gif&quot; alt=&quot;Next&quot; /&gt;&lt;/a&gt; 
  &lt;/div&gt;
  &lt;div class=&quot;overclear top&quot;&gt;
    &lt;img src=&quot;images/books_left_top.gif&quot; alt=&quot;&quot; class=&quot;float_left&quot; /&gt;
    &lt;img src=&quot;images/books_right_top.gif&quot; alt=&quot;&quot; class=&quot;float_right&quot; /&gt;
  &lt;/div&gt;
  &lt;div class=&quot;inner&quot;&gt;
    &lt;ul class=&quot;overclear&quot;&gt;
      &lt;li class=&quot;loader&quot;&gt;&lt;!-- loader --&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;div class=&quot;overclear btm&quot;&gt;
    &lt;img src=&quot;images/books_left_btm.gif&quot; alt=&quot;&quot; class=&quot;float_left&quot; /&gt;
    &lt;img src=&quot;images/books_right_btm.gif&quot; alt=&quot;&quot; class=&quot;float_right&quot; /&gt;
  &lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<h3>2.CSS代码：</h3>

<div class="wp_codebox"><table><tr id="p177175"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code" id="p177code175"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span>/<span style="color: #933;">16px</span> Verdana<span style="color: #00AA00;">,</span> Geneva<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> hide-focus<span style="color: #00AA00;">:</span>expression<span style="color: #00AA00;">&#40;</span>this.hideFocus<span style="color: #00AA00;">=</span>true<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#books</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">500px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.prev</span> img<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.next</span> img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
.<span style="color: #000000; font-weight: bold;">top</span> img<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.btm</span> img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.overclear</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">1%</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.float_left</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.float_right</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
.<span style="color: #000000; font-weight: bold;">top</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/books_top.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.btm</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/books_btm.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.buttons</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">32px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.prev</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.next</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.showing</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">80%</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #3333ff;">:Tahoma</span><span style="color: #00AA00;">,</span> Geneva<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">4px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.inner</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">125px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/books_left_mid.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-y</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.inner</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/books_right_mid.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-y</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">100%</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.loader</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/books_loader.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #933;">50%</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">;;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">100%</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.book</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">90px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.book</span> <span style="color: #6666ff;">.info</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">107px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">88px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.book</span> <span style="color: #6666ff;">.thumb</span> img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ddd</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.books-tooltip</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.books-tooltip</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">320px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.books-info</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">70px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>
为了兼容ie6，需在head标签内加上代码：</p>

<div class="wp_codebox"><table><tr id="p177176"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p177code176"><pre class="html" style="font-family:monospace;">&lt;!--[if lt IE 7]&gt;
&lt;style type=&quot;text/css&quot;&gt;
    .book { padding-right:12.5px;}
&lt;/style&gt;
&lt; ![end if]--&gt;</pre></td></tr></table></div>

</p>
<h3>3.xml代码：</h3>
<p>因为代码过长的原因，不在此贴出，请阅读外部链接的源代码：<a href="http://www.ihiro.org/cases/bookShow/books.xml" rel="external">XML</a></p>
<p><h3>4.jQuery代码：</h3>

<div class="wp_codebox"><table><tr id="p177177"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
</pre></td><td class="code" id="p177code177"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> perNum <span style="color: #339933;">=</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">;</span>		<span style="color: #006600; font-style: italic;">//每页显示的书本数目</span>
	<span style="color: #003366; font-weight: bold;">var</span> currentPage <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>		<span style="color: #006600; font-style: italic;">//默认显示第一页</span>
	<span style="color: #003366; font-weight: bold;">var</span> startPos <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>		<span style="color: #006600; font-style: italic;">//默认从第一本书开始显示</span>
	<span style="color: #003366; font-weight: bold;">var</span> endPos <span style="color: #339933;">=</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">;</span>			<span style="color: #006600; font-style: italic;">//显示4本书</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//从xml中获得数据，并与html结合</span>
	$.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'books.xml'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.inner ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #003366; font-weight: bold;">var</span> length <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'book'</span><span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>	
&nbsp;
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'book'</span><span style="color: #339933;">,</span> data<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #003366; font-weight: bold;">var</span> $book <span style="color: #339933;">=</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: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> link <span style="color: #339933;">=</span> $book.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> title <span style="color: #339933;">=</span> $book.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'title'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> author <span style="color: #339933;">=</span> $book.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'author'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> imageSrc <span style="color: #339933;">=</span> $book.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'src'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> total <span style="color: #339933;">=</span> $book.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'total'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> average_rating <span style="color: #339933;">=</span> $book.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'average_rating'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #003366; font-weight: bold;">var</span> html <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&amp;lt;li class=&quot;book&quot;&amp;gt;'</span><span style="color: #339933;">;</span>
			html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;a class=&quot;info&quot; href=&quot;'</span> <span style="color: #339933;">+</span> link <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&amp;gt;'</span><span style="color: #339933;">;</span>
			html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;img src=&quot;images/books_info.gif&quot; alt=&quot;more info&quot; /&amp;gt;'</span><span style="color: #339933;">;</span>
			html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;/a&amp;gt;'</span><span style="color: #339933;">;</span>			
			html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;a class=&quot;thumb&quot; href=&quot;'</span> <span style="color: #339933;">+</span> link <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; title=&quot;'</span> <span style="color: #339933;">+</span> title <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot;&amp;gt;'</span><span style="color: #339933;">;</span>
			html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;img src=&quot;'</span> <span style="color: #339933;">+</span> imageSrc <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; alt=&quot;'</span> <span style="color: #339933;">+</span>  title <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; /&amp;gt;'</span><span style="color: #339933;">;</span>
			html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;/a&amp;gt;'</span><span style="color: #339933;">;</span>
			html <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;/li&amp;gt;'</span><span style="color: #339933;">;</span>
&nbsp;
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#books ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>html<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #003366; font-weight: bold;">var</span> bookToolTip <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&amp;lt;div id=&quot;books_ToolTip'</span> <span style="color: #339933;">+</span> index <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; class=&quot;books-tooltip&quot;&amp;gt;'</span><span style="color: #339933;">;</span>
			bookToolTip <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;div class=&quot;books_pointer_left&quot;&amp;gt;&amp;lt;/div&amp;gt;'</span><span style="color: #339933;">;</span>
			bookToolTip <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;div class=&quot;books-info&quot;&amp;gt;'</span><span style="color: #339933;">;</span>
			bookToolTip <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;p&amp;gt;'</span> <span style="color: #339933;">+</span> title <span style="color: #339933;">+</span> <span style="color: #3366CC;">'(by&amp;lt;em&amp;gt;'</span> <span style="color: #339933;">+</span> author <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;lt;/em&amp;gt;)&amp;lt;/p&amp;gt;'</span><span style="color: #339933;">;</span>
			bookToolTip <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;p&amp;gt;&amp;lt;img src=&quot;images/stars_'</span> <span style="color: #339933;">+</span> average_rating <span style="color: #339933;">+</span> <span style="color: #3366CC;">'.gif&quot; /&amp;gt;('</span> <span style="color: #339933;">+</span> total <span style="color: #339933;">+</span> <span style="color: #3366CC;">')&amp;lt;/p&amp;gt;'</span><span style="color: #339933;">;</span>
			bookToolTip <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;/div&amp;gt;'</span><span style="color: #339933;">;</span>
			bookToolTip <span style="color: #339933;">+=</span> <span style="color: #3366CC;">'&amp;lt;/div&amp;gt;'</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>bookToolTip<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//显示每页的书本</span>
		<span style="color: #003366; font-weight: bold;">var</span> show <span style="color: #339933;">=</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>start<span style="color: #339933;">,</span> end<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>end <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> length<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				end <span style="color: #339933;">=</span> length<span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.showing'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&amp;lt;p&amp;gt;Viewing '</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>start<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' - '</span><span style="color: #339933;">+</span> end <span style="color: #339933;">+</span> <span style="color: #3366CC;">' of '</span> <span style="color: #339933;">+</span> length <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&amp;lt;/p&amp;gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.showing'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#books ul li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slice</span><span style="color: #009900;">&#40;</span>start<span style="color: #339933;">,</span> end<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>currentPage <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.prev'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</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;">else</span> <span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.prev'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</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>currentPage <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> length <span style="color: #339933;">/</span> perNum<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.next'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</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;">else</span> <span style="color: #009900;">&#123;</span>
				$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.next'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</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>
		show<span style="color: #009900;">&#40;</span>startPos<span style="color: #339933;">,</span> endPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//显示前一页</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.prev'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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>
			currentPage <span style="color: #339933;">--;</span>
			startPos <span style="color: #339933;">=</span> perNum <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>currentPage <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			endPos <span style="color: #339933;">=</span> perNum <span style="color: #339933;">*</span> currentPage<span style="color: #339933;">;</span>
			show<span style="color: #009900;">&#40;</span>startPos<span style="color: #339933;">,</span> endPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//显示下一页</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.next'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</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>
			currentPage <span style="color: #339933;">++;</span>
			startPos <span style="color: #339933;">=</span> perNum <span style="color: #339933;">*</span> <span style="color: #009900;">&#40;</span>currentPage <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			endPos <span style="color: #339933;">=</span> perNum <span style="color: #339933;">*</span> currentPage<span style="color: #339933;">;</span>
			show<span style="color: #009900;">&#40;</span>startPos<span style="color: #339933;">,</span> endPos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//鼠标移动到Info图标上时，显示书本的描述信息</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.info'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'opacity'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'0.9'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</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: #006600; font-style: italic;">//$('a.info').index(this)   获得该超链接的index</span>
			<span style="color: #003366; font-weight: bold;">var</span> offset <span style="color: #339933;">=</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: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #003366; font-weight: bold;">var</span> left <span style="color: #339933;">=</span> offset.<span style="color: #660066;">left</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> top <span style="color: #339933;">=</span> offset.<span style="color: #660066;">top</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#books_ToolTip'</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.info'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">index</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;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'opacity'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'0.7'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'left'</span><span style="color: #339933;">:</span> left<span style="color: #339933;">,</span> <span style="color: #3366CC;">'top'</span><span style="color: #339933;">:</span> top<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fadeIn</span><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: #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: #009900;">&#40;</span><span style="color: #3366CC;">'#books_ToolTip'</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a.info'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">index</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;">&#41;</span>.<span style="color: #660066;">fadeOut</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>
</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2009年08月28日 -- <a href="http://www.ihiro.org/jquery-hot-pictures-showing-effects-of-rotation" title="jQuery:热点图片轮换展示效果">jQuery:热点图片轮换展示效果</a> (14)</li><li>2009年07月14日 -- <a href="http://www.ihiro.org/keyboard-simulation-with-css-and-jquery" title="jQuery:使用css+jQuery模拟键盘">jQuery:使用css+jQuery模拟键盘</a> (10)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/the-effection-of-tab-like-msn" title="jQuery:仿MSN网站的tab效果">jQuery:仿MSN网站的tab效果</a> (30)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/a-simple-6-lines-of-code-to-achieve-the-tab-effecttion" title="jQuery：简单6行代码实现tab效果">jQuery：简单6行代码实现tab效果</a> (10)</li><li>2009年06月30日 -- <a href="http://www.ihiro.org/the-effection-of-thunder-home-page" title="jQuery：仿迅雷首页热片滑动效果">jQuery：仿迅雷首页热片滑动效果</a> (6)</li><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年07月6日 -- <a href="http://www.ihiro.org/pure-css-dynamic-page-effects" title="CSS:纯css的伪动态分页效果">CSS:纯css的伪动态分页效果</a> (17)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/the-effection-of-books-show/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>CSS:纯css的伪动态分页效果</title>
		<link>http://www.ihiro.org/pure-css-dynamic-page-effects</link>
		<comments>http://www.ihiro.org/pure-css-dynamic-page-effects#comments</comments>
		<pubDate>Mon, 06 Jul 2009 02:29:46 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[CSS、XHTML]]></category>
		<category><![CDATA[Cases]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=139</guid>
		<description><![CDATA[<p>使用css编写的一个动态分页效果，通过使用opacity和filter实现透明效果，分页效果如下：</p>
<iframe src="http://www.ihiro.org/cases/pageNav/" width="450px" height="40px"></iframe>]]></description>
			<content:encoded><![CDATA[<p>使用css编写的一个动态分页效果，通过使用opacity和filter实现透明效果，分页效果如下：</p>
<p><iframe src="http://www.ihiro.org/cases/pageNav/" width="450px" height="40px"></iframe></p>
<h3>1.Html代码：</h3>

<div class="wp_codebox"><table><tr id="p139178"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p139code178"><pre class="html" style="font-family:monospace;">&lt;ul id=&quot;pageNav&quot;&gt;
	&lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;arrow&quot;&gt;&lt; &lt;&lt;/a&gt;&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;currPage&quot;&gt;1&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;2&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;3&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;4&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;5&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;6&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;7&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;8&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;9&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;10&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;11&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;12&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;13&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;14&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot;&gt;15&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href=&quot;#&quot; class=&quot;arrow&quot;&gt;&gt;&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</pre></td></tr></table></div>

<h3>2.css代码：</h3>

<div class="wp_codebox"><table><tr id="p139179"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p139code179"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">11px</span> Verdana<span style="color: #00AA00;">,</span> Geneva<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #cc00cc;">#pageNav</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#pageNav</span> li a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#666</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-1px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">pageNav-bg.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#pageNav</span> li a<span style="color: #6666ff;">.currPage</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#pageNav</span> li a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">4px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">-2px</span> <span style="color: #933;">-10px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> opacity<span style="color: #00AA00;">:</span>.9<span style="color: #00AA00;">;</span> filter<span style="color: #00AA00;">:</span>Alpha<span style="color: #00AA00;">&#40;</span>opacity<span style="color: #00AA00;">=</span><span style="color: #cc66cc;">90</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#pageNav</span> li a<span style="color: #6666ff;">.arrow</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">static</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">-1px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>说明：本特效主要的要点在：a:hover时position:relative和margin:-2px -10px 0。为了兼容ie6，需要设置#pageNav li a { display:block; float:left;}</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2009年08月28日 -- <a href="http://www.ihiro.org/jquery-hot-pictures-showing-effects-of-rotation" title="jQuery:热点图片轮换展示效果">jQuery:热点图片轮换展示效果</a> (14)</li><li>2009年07月14日 -- <a href="http://www.ihiro.org/keyboard-simulation-with-css-and-jquery" title="jQuery:使用css+jQuery模拟键盘">jQuery:使用css+jQuery模拟键盘</a> (10)</li><li>2009年07月10日 -- <a href="http://www.ihiro.org/the-effection-of-books-show" title="jQuery:书籍展示效果">jQuery:书籍展示效果</a> (6)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/the-effection-of-tab-like-msn" title="jQuery:仿MSN网站的tab效果">jQuery:仿MSN网站的tab效果</a> (30)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/a-simple-6-lines-of-code-to-achieve-the-tab-effecttion" title="jQuery：简单6行代码实现tab效果">jQuery：简单6行代码实现tab效果</a> (10)</li><li>2009年06月30日 -- <a href="http://www.ihiro.org/the-effection-of-thunder-home-page" title="jQuery：仿迅雷首页热片滑动效果">jQuery：仿迅雷首页热片滑动效果</a> (6)</li><li>2011年03月2日 -- <a href="http://www.ihiro.org/css-specific-for-internet-explorer" title="CSS:区分IE版本的三个方法">CSS:区分IE版本的三个方法</a> (27)</li><li>2011年02月24日 -- <a href="http://www.ihiro.org/scroll-images" title="Javascript:图片无限循环滚动">Javascript:图片无限循环滚动</a> (27)</li><li>2010年11月25日 -- <a href="http://www.ihiro.org/css-position-hack" title="CSS:position属性定位总结">CSS:position属性定位总结</a> (28)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/pure-css-dynamic-page-effects/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>jQuery:仿MSN网站的tab效果</title>
		<link>http://www.ihiro.org/the-effection-of-tab-like-msn</link>
		<comments>http://www.ihiro.org/the-effection-of-tab-like-msn#comments</comments>
		<pubDate>Thu, 02 Jul 2009 09:51:21 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[案例分享]]></category>
		<category><![CDATA[Cases]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=134</guid>
		<description><![CDATA[今天不知怎的，一直在做tab的特效，看到MSN官网的tab效果不错，就花了一点点时间小做了一下，具体效果：如下
<iframe src="http://www.ihiro.org/cases/tabs-msn/" width="400px" height="280px" style="border:none; overflow:hidden; margin:5px 0;"></iframe>]]></description>
			<content:encoded><![CDATA[<p>今天不知怎的，一直在做tab的特效，看到MSN官网的tab效果不错，就花了一点点时间小做了一下，具体效果：如下<br />
<iframe src="http://www.ihiro.org/cases/tabs-msn/" width="400px" height="280px" style="border:none; overflow:hidden; margin:5px 0;"></iframe></p>
<h3>html代码：</h3>
<p>因为过长的原因，请有意的朋友通过此链接查看外部效果，右键查看源文件！<a href="http://www.ihiro.org/cases/tabs-msn/" rel="external">External Link</a></p>
<h3>css代码：</h3>

<div class="wp_codebox"><table><tr id="p134180"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p134code180"><pre class="css" style="font-family:monospace;">       <span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span> <span style="color: #ff0000;">&quot;宋体&quot;</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#049</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">8px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#049</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">underline</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">23px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">23px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #6666ff;">.popular</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">298px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ace</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
		<span style="color: #6666ff;">.tabs</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">1%</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #6666ff;">.tabs</span> li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ace</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#f1f7fc</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">84px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #6666ff;">.tabs</span> li<span style="color: #6666ff;">.active</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-bottom-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #6666ff;">.tabs</span> li<span style="color: #6666ff;">.tab-r</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">118px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
				<span style="color: #6666ff;">.tabs</span> li<span style="color: #6666ff;">.tab-r</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F06</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span>Georgia<span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
		<span style="color: #6666ff;">.list</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">7px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">7px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">popularlist.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
		<span style="color: #6666ff;">.weeklyPopular</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>jQuery代码：</h3>

<div class="wp_codebox"><table><tr id="p134181"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code" id="p134code181"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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: #009900;">&#40;</span><span style="color: #3366CC;">'a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'target'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'_blank'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.tabs li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mousemove</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: #006600; font-style: italic;">//最右边的tab不进行任何操作							 </span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</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: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tab-r'</span><span style="color: #009900;">&#41;</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><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">//添加当前激活的状态</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: #660066;">siblings</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'active'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
			.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'active'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">//切换tab		</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</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: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tab-0'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.dairyPopular'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		        <span style="color: #006600; font-style: italic;">//也可以写成$(this).parent().nextAll('ul:eq(0)').show();,这样的好处是不必制定特定的class类</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</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: #660066;">hasClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tab-1'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.weeklyPopular'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">//也可以写成$(this).parent().nextAll('ul:eq(1)').show();,这样的好处是不必制定特定的class类</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>需要源码包的朋友可以给我留言，我会发到你的邮箱中！</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2009年08月28日 -- <a href="http://www.ihiro.org/jquery-hot-pictures-showing-effects-of-rotation" title="jQuery:热点图片轮换展示效果">jQuery:热点图片轮换展示效果</a> (14)</li><li>2009年07月14日 -- <a href="http://www.ihiro.org/keyboard-simulation-with-css-and-jquery" title="jQuery:使用css+jQuery模拟键盘">jQuery:使用css+jQuery模拟键盘</a> (10)</li><li>2009年07月10日 -- <a href="http://www.ihiro.org/the-effection-of-books-show" title="jQuery:书籍展示效果">jQuery:书籍展示效果</a> (6)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/a-simple-6-lines-of-code-to-achieve-the-tab-effecttion" title="jQuery：简单6行代码实现tab效果">jQuery：简单6行代码实现tab效果</a> (10)</li><li>2009年06月30日 -- <a href="http://www.ihiro.org/the-effection-of-thunder-home-page" title="jQuery：仿迅雷首页热片滑动效果">jQuery：仿迅雷首页热片滑动效果</a> (6)</li><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年07月6日 -- <a href="http://www.ihiro.org/pure-css-dynamic-page-effects" title="CSS:纯css的伪动态分页效果">CSS:纯css的伪动态分页效果</a> (17)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/the-effection-of-tab-like-msn/feed</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>jQuery：简单6行代码实现tab效果</title>
		<link>http://www.ihiro.org/a-simple-6-lines-of-code-to-achieve-the-tab-effecttion</link>
		<comments>http://www.ihiro.org/a-simple-6-lines-of-code-to-achieve-the-tab-effecttion#comments</comments>
		<pubDate>Thu, 02 Jul 2009 02:37:57 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[案例分享]]></category>
		<category><![CDATA[Cases]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=120</guid>
		<description><![CDATA[简简单单的6行代码实现tab滑动门效果：如下
<iframe src="http://www.ihiro.org/cases/tabs/" width="420px" height="170px" style=" overflow:hidden; border:none; margin:10px 0 10px 0;"></iframe>]]></description>
			<content:encoded><![CDATA[<p>简简单单的6行代码实现tab滑动门效果：如下<br />
<iframe src="http://www.ihiro.org/cases/tabs/" width="420px" height="170px"></iframe></p>
<h3>html代码：</h3>

<div class="wp_codebox"><table><tr id="p120182"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p120code182"><pre class="html" style="font-family:monospace;">    &lt;div class=&quot;tabs&quot;&gt;
    	&lt;!-- 默认第一个tab为激活状态 --&gt;
        &lt;h3 class=&quot;active&quot;&gt;&lt;span&gt;热点新闻&lt;/span&gt;&lt;/h3&gt;
        &lt;div id=&quot;tab-01&quot;&gt;news&lt;/div&gt;
	    &lt;h3&gt;&lt;span&gt;娱乐新闻&lt;/span&gt;&lt;/h3&gt;
        &lt;div id=&quot;tab-02&quot;&gt;enteriment&lt;/div&gt;
        &lt;h3&gt;&lt;span&gt;就业形势&lt;/span&gt;&lt;/h3&gt;
        &lt;div id=&quot;tab-03&quot;&gt;jobs&lt;/div&gt;
    &lt;/div&gt;</pre></td></tr></table></div>

<h3>CSS代码：</h3>

<div class="wp_codebox"><table><tr id="p120183"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p120code183"><pre class="css" style="font-family:monospace;">    <span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
    body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span> Verdana<span style="color: #00AA00;">,</span> Geneva<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#404040</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #6666ff;">.tabs</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">360px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">1%</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">140px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.tabs</span> h3 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">2</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">pic.gif</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">95px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">5px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		h3<span style="color: #6666ff;">.active</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">-25px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #cc00cc;">#tab-01</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#tab-02</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#tab-03</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">24px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">338px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">93px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ace</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #cc00cc;">#tab-02</span><span style="color: #00AA00;">,</span> <span style="color: #cc00cc;">#tab-03</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>jQuery代码：</h3>

<div class="wp_codebox"><table><tr id="p120184"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p120code184"><pre class="javascript" style="font-family:monospace;">    $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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: #009900;">&#40;</span><span style="color: #3366CC;">'.tabs h3'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mouseover</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: #009900;">&#40;</span><span style="color: #3366CC;">'.tabs div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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: #660066;">siblings</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'h3'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'active'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
					  .<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'active'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><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;">&#41;</span><span style="color: #339933;">;</span>	
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>具体效果也可查看：<a href="http://www.ihiro.org/cases/tabs/" rel="external">效果查看</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2009年08月28日 -- <a href="http://www.ihiro.org/jquery-hot-pictures-showing-effects-of-rotation" title="jQuery:热点图片轮换展示效果">jQuery:热点图片轮换展示效果</a> (14)</li><li>2009年07月14日 -- <a href="http://www.ihiro.org/keyboard-simulation-with-css-and-jquery" title="jQuery:使用css+jQuery模拟键盘">jQuery:使用css+jQuery模拟键盘</a> (10)</li><li>2009年07月10日 -- <a href="http://www.ihiro.org/the-effection-of-books-show" title="jQuery:书籍展示效果">jQuery:书籍展示效果</a> (6)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/the-effection-of-tab-like-msn" title="jQuery:仿MSN网站的tab效果">jQuery:仿MSN网站的tab效果</a> (30)</li><li>2009年06月30日 -- <a href="http://www.ihiro.org/the-effection-of-thunder-home-page" title="jQuery：仿迅雷首页热片滑动效果">jQuery：仿迅雷首页热片滑动效果</a> (6)</li><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年07月6日 -- <a href="http://www.ihiro.org/pure-css-dynamic-page-effects" title="CSS:纯css的伪动态分页效果">CSS:纯css的伪动态分页效果</a> (17)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/a-simple-6-lines-of-code-to-achieve-the-tab-effecttion/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>jQuery：仿迅雷首页热片滑动效果</title>
		<link>http://www.ihiro.org/the-effection-of-thunder-home-page</link>
		<comments>http://www.ihiro.org/the-effection-of-thunder-home-page#comments</comments>
		<pubDate>Tue, 30 Jun 2009 14:27:39 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[案例分享]]></category>
		<category><![CDATA[Cases]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=109</guid>
		<description><![CDATA[一直都很喜欢迅雷网站的设计，前端时间迅雷更新的主页的css风格，没了以前的tab效果，多了点变幻滑动的效果。
今天花了点时间，模仿了一下当前迅雷主页上的热点电视、电影的滑动效果简简单单的6行代码实现tab滑动门效果：如下
<iframe src="http://www.ihiro.org/cases/movieshow/index.html" width="500" height="220"></iframe>]]></description>
			<content:encoded><![CDATA[<p>一直都很喜欢迅雷网站的设计，前端时间迅雷更新的主页的css风格，没了以前的tab效果，多了点变幻滑动的效果。<br />
今天花了点时间，模仿了一下当前迅雷主页上的热点电视、电影的滑动效果：如下<br />
<iframe src="http://www.ihiro.org/cases/movieshow/index.html" width="500" height="220"></iframe></p>
<h3>模仿说明：</h3>
<p>1. 因为时间的关系，没有花时间去解决ie6下图片透明的兼容；<br />
2. 在兼容各浏览器编写时花费的时间较多，实现了多浏览器的兼容性，除了图片透明的问题（时间关系）；<br />
3. 运用jQuery库对javascript进行编写；<br />
4. 采用css sprite技术处理背景定位；<br />
5. 计划实现自动播放效果。</p>
<h3>代码说明：</h3>
<p><strong>一. CSS代码：</strong></p>

<div class="wp_codebox"><table><tr id="p109185"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
</pre></td><td class="code" id="p109code185"><pre class="css" style="font-family:monospace;">html<span style="color: #00AA00;">,</span>body<span style="color: #00AA00;">,</span>
ul<span style="color: #00AA00;">,</span>ol<span style="color: #00AA00;">,</span>li<span style="color: #00AA00;">,</span>dl<span style="color: #00AA00;">,</span>dt<span style="color: #00AA00;">,</span>dd<span style="color: #00AA00;">,</span>
h1<span style="color: #00AA00;">,</span>h2<span style="color: #00AA00;">,</span>h3<span style="color: #00AA00;">,</span>h4<span style="color: #00AA00;">,</span>h5<span style="color: #00AA00;">,</span>h6<span style="color: #00AA00;">,</span>
form<span style="color: #00AA00;">,</span>input<span style="color: #00AA00;">,</span>blockquote<span style="color: #00AA00;">,</span>fieldset<span style="color: #00AA00;">,</span>pre<span style="color: #00AA00;">,</span>
div<span style="color: #00AA00;">,</span>p<span style="color: #00AA00;">,</span>span<span style="color: #00AA00;">,</span>label<span style="color: #00AA00;">,</span>em<span style="color: #00AA00;">,</span>strong <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFFFFF</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #993333;">normal</span> <span style="color: #933;">12px</span>/<span style="color: #933;">20px</span> Arial<span style="color: #00AA00;">,</span> Verdana<span style="color: #00AA00;">,</span> Lucida<span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span> simsun<span style="color: #00AA00;">,</span> <span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#313131</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #6666ff;">.huanying</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">468px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">208px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.huanying</span> h2 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">27px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">27px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/pic.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">13px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#193b5f</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">11px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.huanying</span> .<span style="color: #000000; font-weight: bold;">content</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#CCDFF2</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-top-width</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">466px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">180px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #6666ff;">.movList</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span> <span style="color: #933;">8px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.movList</span> ul <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">8px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">432px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.movList</span> ul<span style="color: #cc00cc;">#ul_hp_0</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.movList</span> ul<span style="color: #cc00cc;">#ul_hp_1</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.movList</span> ul<span style="color: #cc00cc;">#ul_hp_2</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">500px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.movList</span> ul li <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">92px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">8px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">/* ----- 封面 ----- */</span>
			<span style="color: #6666ff;">.movList</span> ul li a<span style="color: #6666ff;">.playpic</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">92px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">127px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #6666ff;">.movList</span> ul li a<span style="color: #6666ff;">.playpic</span> img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#eae4d1</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #6666ff;">.movList</span> ul li a<span style="color: #6666ff;">.playpic</span> em <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #6666ff;">.movList</span> ul li a<span style="color: #6666ff;">.playpic</span><span style="color: #3333ff;">:hover </span>em <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">31px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">31px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/pic.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #933;">-95px</span> <span style="color: #933;">-28px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">48px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">30.5px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #808080; font-style: italic;">/* ----- 集数 ----- */</span>
			<span style="color: #6666ff;">.movList</span> ul li a<span style="color: #6666ff;">.playpic</span> span <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">86px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">15px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">15px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">3px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #6666ff;">.movList</span> ul li a<span style="color: #6666ff;">.playpic</span> span<span style="color: #6666ff;">.bg</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/pic.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #933;">-130px</span> <span style="color: #933;">-28px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
			<span style="color: #808080; font-style: italic;">/* ----- 标题和简短描述 ----- */</span>
			<span style="color: #6666ff;">.movList</span> ul li p <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">17px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">17px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">center</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #6666ff;">.movList</span> ul li p<span style="color: #6666ff;">.mov-title</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">82px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #6666ff;">.movList</span> ul li p<span style="color: #6666ff;">.mov-title</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#016a9f</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #6666ff;">.movList</span> ul li p<span style="color: #6666ff;">.mov-title</span> a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">underline</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
			<span style="color: #6666ff;">.movList</span> ul li p<span style="color: #6666ff;">.mov-title</span> a<span style="color: #6666ff;">.playMov</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">16px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/pic.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #933;">-240px</span> <span style="color: #933;">-28px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #6666ff;">.list-pager</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">75px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">18px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span><span style="color: #933;">4px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span><span style="color: #933;">11px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.list-pager</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">text-indent</span><span style="color: #00AA00;">:</span><span style="color: #933;">-9999px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/* ----- page-num ----- */</span>
	<span style="color: #6666ff;">.pager-num</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">33px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">18px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.pager-num</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">6px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">6px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/pic.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #933;">-80px</span> <span style="color: #933;">-28px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">6px</span> <span style="color: #933;">5px</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.pager-num</span> a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #933;">-80px</span> <span style="color: #933;">-38px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #808080; font-style: italic;">/* ----- selected ----- */</span>
		<span style="color: #6666ff;">.currentNum</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/pic.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #933;">-80px</span> <span style="color: #933;">-38px</span>!important<span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">/* ----- prev next ----- */</span>
	<span style="color: #6666ff;">.pager-op</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">36px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.pager-op</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">18px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">18px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/pic.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.pager-op</span> a<span style="color: #6666ff;">.page-up</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #933;">-40px</span> <span style="color: #933;">-28px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.pager-op</span> a<span style="color: #6666ff;">.page-up</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #933;">-28px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.pager-op</span> a<span style="color: #6666ff;">.page-down</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #933;">-17px</span> <span style="color: #933;">-28px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.pager-op</span> a<span style="color: #6666ff;">.page-down</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span><span style="color: #933;">-57px</span> <span style="color: #933;">-28px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p><strong>二. jQuery代码：</strong></p>

<div class="wp_codebox"><table><tr id="p109186"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
</pre></td><td class="code" id="p109code186"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*
 * 时间关系，未修复IE6下图像透明的问题。
 */</span>
&nbsp;
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</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>
&nbsp;
	<span style="color: #006600; font-style: italic;">//修复IE6的：hover</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.movList ul li a.playpic'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hover</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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'em'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'block'</span><span style="color: #009900;">&#125;</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: #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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'em'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'display'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'none'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> lenght <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#div_hp_content ul'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">// currId-&gt;当前显示页， clickId-&gt;点击页面的标记</span>
	<span style="color: #003366; font-weight: bold;">var</span> currId <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> clickId <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">// 获得需滑动的整体对象</span>
	<span style="color: #003366; font-weight: bold;">var</span> $box <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#div_hp_content ul'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>currId <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		currId <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>currId <span style="color: #339933;">&gt;=</span> lenght <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		currId <span style="color: #339933;">=</span> lenght<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.pager-num a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">//获得当前点击对象的id值</span>
		<span style="color: #003366; font-weight: bold;">var</span> index <span style="color: #339933;">=</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: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		checkIndex<span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//判断当前点击页数，若当前点击页数大于当前显示页，向左滑动</span>
		<span style="color: #006600; font-style: italic;">//若当前点击页数小于当前显示页，向右滑动</span>
		<span style="color: #006600; font-style: italic;">//否则不进行任何操作</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>clickId <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> currId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$box.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span>currId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'left'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'-480px'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span>
						   .<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span>clickId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'left'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'10px'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>clickId <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> currId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$box.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span>currId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'left'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'480px'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span>
						   .<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span>clickId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'left'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'10px'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">//设置当前显示页标记等于点击的页数</span>
		currId <span style="color: #339933;">=</span> clickId<span style="color: #339933;">;</span>
		changeSelected<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		event.<span style="color: #660066;">preventDefault</span><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;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//上一页</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.page-up'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<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>currId <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span> <span style="color: #CC0000;">0</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: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		$box.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span>currId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'left'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'480px'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span>
					   .<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span>currId <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'left'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'10px'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		currId<span style="color: #339933;">--;</span>
		changeSelected<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		event.<span style="color: #660066;">preventDefault</span><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;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">//下一页</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.page-down'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>event<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>currId <span style="color: #339933;">&gt;=</span> lenght <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</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: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
		$box.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span>currId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'left'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'-480px'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span>
					   .<span style="color: #660066;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span>currId <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'left'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'10px'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'slow'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		currId<span style="color: #339933;">++;</span>
		changeSelected<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		event.<span style="color: #660066;">preventDefault</span><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;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//点击页数按钮检查index</span>
	<span style="color: #003366; font-weight: bold;">var</span> checkIndex <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>index<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'a_hp_0'</span><span style="color: #339933;">:</span>
			clickId <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'a_hp_1'</span><span style="color: #339933;">:</span>
			clickId <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'a_hp_2'</span><span style="color: #339933;">:</span>
			clickId <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">break</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>
&nbsp;
	<span style="color: #006600; font-style: italic;">//改变当前所选择的页数</span>
	<span style="color: #003366; font-weight: bold;">var</span> changeSelected <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: #009900;">&#40;</span><span style="color: #3366CC;">'.pager-num a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'currentNum'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">eq</span><span style="color: #009900;">&#40;</span>currId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'currentNum'</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: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>题外话：</h3>
<p>呵呵，因为图片都是从迅雷网站上下载，有点小剽窃的感觉哦。不过，在这效果上有链接到迅雷相关电视、电影页面，也算给他做个小小的推广。大家就算扯平了吧。</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2009年08月28日 -- <a href="http://www.ihiro.org/jquery-hot-pictures-showing-effects-of-rotation" title="jQuery:热点图片轮换展示效果">jQuery:热点图片轮换展示效果</a> (14)</li><li>2009年07月14日 -- <a href="http://www.ihiro.org/keyboard-simulation-with-css-and-jquery" title="jQuery:使用css+jQuery模拟键盘">jQuery:使用css+jQuery模拟键盘</a> (10)</li><li>2009年07月10日 -- <a href="http://www.ihiro.org/the-effection-of-books-show" title="jQuery:书籍展示效果">jQuery:书籍展示效果</a> (6)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/the-effection-of-tab-like-msn" title="jQuery:仿MSN网站的tab效果">jQuery:仿MSN网站的tab效果</a> (30)</li><li>2009年07月2日 -- <a href="http://www.ihiro.org/a-simple-6-lines-of-code-to-achieve-the-tab-effecttion" title="jQuery：简单6行代码实现tab效果">jQuery：简单6行代码实现tab效果</a> (10)</li><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li><li>2009年11月26日 -- <a href="http://www.ihiro.org/jquery-enhanced-marquee-bulletin-board" title="jQuery:增强型走马灯公告栏，可以抛弃marquee标签了">jQuery:增强型走马灯公告栏，可以抛弃marquee标签了</a> (20)</li><li>2009年09月23日 -- <a href="http://www.ihiro.org/ajax-editing-in-placing" title="Ajax:当前页面更改内容，前端实现">Ajax:当前页面更改内容，前端实现</a> (14)</li><li>2009年07月6日 -- <a href="http://www.ihiro.org/pure-css-dynamic-page-effects" title="CSS:纯css的伪动态分页效果">CSS:纯css的伪动态分页效果</a> (17)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/the-effection-of-thunder-home-page/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>简谈新窗口打开超链接的技巧</title>
		<link>http://www.ihiro.org/a-simple-talk-about-the-hyperlink-to-open-a-new-window-techniques</link>
		<comments>http://www.ihiro.org/a-simple-talk-about-the-hyperlink-to-open-a-new-window-techniques#comments</comments>
		<pubDate>Fri, 19 Jun 2009 16:09:07 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[技巧]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=75</guid>
		<description><![CDATA[超链接跳转常用在友情链接中，或链接到其他网站，为了可以把你的访问者继续留在自己的主页而使用的一个技巧。现在我就要说说常用的几种跳转技巧：
1.使用html标签的target属性；
2.使用Javascript代码。
]]></description>
			<content:encoded><![CDATA[<p>超链接跳转常用在友情链接中，或链接到其他网站，为了可以把你的访问者继续留在自己的主页而使用的一个技巧。现在我就要说说常用的几种跳转技巧：</p>
<h3>1.使用html标签的target属性：</h3>
<p>该方法恐怕是大家使用最多的方法，也是所有web工具所默认的。只需在链接a标签中加入属性target属性即可：如下</p>

<div class="wp_codebox"><table><tr id="p75187"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p75code187"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;http://www.ihiro.org/ title=&quot;Hiro's Blog&quot; target=&quot;_blank&quot;&gt;www.ihiro.org&lt;/a&gt;</pre></td></tr></table></div>

<p>在web标准流行的当代，也许大家已经发现，该方法不能通过W3C的验证。</p>
<h3>2.使用Javascript代码:</h3>
<p>在a标签中加入rel=“external”属性:如下</p>

<div class="wp_codebox"><table><tr id="p75188"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p75code188"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;http://www.ihiro.org/ title=&quot;Hiro's Blog&quot; rel=&quot;external&quot;&gt;www.ihiro.org&lt;/a&gt;</pre></td></tr></table></div>

<p>运用jQuery框架，在页面中导入js文件，编写代码：如下</p>

<div class="wp_codebox"><table><tr id="p75189"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p75code189"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a[rel*=external]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'target'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'_blank'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>该方法好处是欺骗了浏览器，可以通过W3C的验证。</p>
<h3>附加技巧：</h3>
<p>在一列友情链接都需要跳转时，我们不可能为每个a标签都添加rel=“external”属性.这是可以使用类或id的方法：如下</p>

<div class="wp_codebox"><table><tr id="p75190"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p75code190"><pre class="html" style="font-family:monospace;">&lt;ul class=&quot;external&quot;&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/ title=&quot;Hiro's Blog&quot;&gt;www.ihiro.org&lt;/a&gt; &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/ title=&quot;Hiro's Blog&quot;&gt;www.ihiro.org&lt;/a&gt; &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/ title=&quot;Hiro's Blog&quot;&gt;www.ihiro.org&lt;/a&gt; &lt;/li&gt;
        &lt;li&gt;&lt;a href=&quot;http://www.ihiro.org/ title=&quot;Hiro's Blog&quot;&gt;www.ihiro.org&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;</pre></td></tr></table></div>

<p>jQuery代码：如下</p>

<div class="wp_codebox"><table><tr id="p75191"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p75code191"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ul.external li a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'target'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'_blank'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>这样这个ul列表中的所有友情链接都可以实现页面跳转了。</p>
<h3>总结：</h3>
<p>当然你也可以不使用jQuery框架，直接使用普通的javascript编写也可以实现，但没有jQuery实现的如此优雅。上文中的external其实是可以随便命名的，自需要保持javascriprt中的名称相同即可。</p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2011年03月2日 -- <a href="http://www.ihiro.org/css-specific-for-internet-explorer" title="CSS:区分IE版本的三个方法">CSS:区分IE版本的三个方法</a> (27)</li><li>2010年10月21日 -- <a href="http://www.ihiro.org/jquery-plugin-recommended-maphighlight" title="jQuery:热区高亮maphighlight插件推荐">jQuery:热区高亮maphighlight插件推荐</a> (23)</li><li>2010年09月20日 -- <a href="http://www.ihiro.org/jquery-format-extend" title="jQuery:数字、字符串格式化扩展">jQuery:数字、字符串格式化扩展</a> (31)</li><li>2010年09月2日 -- <a href="http://www.ihiro.org/example-selectbox-simulation" title="示例:Selectbox模拟实现效果">示例:Selectbox模拟实现效果</a> (22)</li><li>2010年08月12日 -- <a href="http://www.ihiro.org/sizzle-custom-selector" title="Sizzle:开源JS选择器，如何自定义选择器">Sizzle:开源JS选择器，如何自定义选择器</a> (31)</li><li>2010年06月30日 -- <a href="http://www.ihiro.org/firebug-console-panel-function" title="Firebug:Javascript测试利器，Console面板函数详解">Firebug:Javascript测试利器，Console面板函数详解</a> (4)</li><li>2010年05月17日 -- <a href="http://www.ihiro.org/target-every-version-of-ie-from-a-single-stylesheet" title="CSS:通过一个样式表区分IE的各个版本">CSS:通过一个样式表区分IE的各个版本</a> (11)</li><li>2010年03月25日 -- <a href="http://www.ihiro.org/the-enhanced-ajax-effect-instructions" title="Ajax:近期博客改版的增强Ajax加载说明">Ajax:近期博客改版的增强Ajax加载说明</a> (43)</li><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年02月26日 -- <a href="http://www.ihiro.org/a-rich-picture-effect-flash" title="jQuery:丰富效果的Flash图片播放（JS重写版）">jQuery:丰富效果的Flash图片播放（JS重写版）</a> (18)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/a-simple-talk-about-the-hyperlink-to-open-a-new-window-techniques/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
