<?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>一起CSS &#187; CSS Expressions</title>
	<atom:link href="http://www.17css.com/tag/css-expressions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.17css.com</link>
	<description>一起CSS，专注、关注CSS等前端技术。</description>
	<lastBuildDate>Tue, 17 Jan 2012 04:59:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CSS Expressions有多可怕</title>
		<link>http://www.17css.com/how-terrible-the-css-expressions/</link>
		<comments>http://www.17css.com/how-terrible-the-css-expressions/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 08:13:12 +0000</pubDate>
		<dc:creator>青色</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS Expressions]]></category>

		<guid isPermaLink="false">http://www.17css.com/?p=471</guid>
		<description><![CDATA[CSS Expressions 俗称 CSS 表达式，避免使用 CSS Expressions 是前端开发的一个重要指南，为什么要避免使用 CSS Expressions 呢？我们看看雅虎YUI的说明： 表达式的问题就在于它的计算频率要比我们想象的... ]]></description>
			<content:encoded><![CDATA[<p>CSS Expressions 俗称 CSS 表达式，避免使用 CSS Expressions 是前端开发的一个重要指南，为什么要避免使用 CSS Expressions 呢？我们看看雅虎YUI的说明：</p>
<div class="quote">
<blockquote>表达式的问题就在于它的计算频率要比我们想象的多。不仅仅是在页面显示和缩放时，就是在页面滚动、乃至移动鼠标时都会要重新计算一次。给CSS表达式增加一个计数器可以跟踪表达式的计算频率。在页面中随便移动鼠标都可以轻松达到10000次以上的计算量。</p></blockquote>
</div>
<p>从上面可以看出 CSS Expressions 是如此的可怕。但也许单纯的文字说明还不能使你深入的明白 CSS Expressions 的可怕，那就引用<a title="子鼠" href="http://www.zishu.cn/blogview.asp?logID=835&amp;cateID=3">子鼠</a>的例子来实际说明吧：</p>
<p>XHTML 和 JS 代码：</p>
<pre class="prettyprint">
&lt;body&gt;
计算了&lt;input id=&quot;c&quot; /&gt;次
&lt;script type=&quot;text/javascript&quot;&gt;
var k = 0;
function test() {
	k++;
	document.getElementById('c').value = k;
	return;
}
&lt;/script&gt;
&lt;div&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;a href=&quot;11111111111111111111&quot;&gt;22222&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;11111111111111111111&quot;&gt;22222&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;11111111111111111111&quot;&gt;22222&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;11111111111111111111&quot;&gt;22222&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/div&gt;
&lt;/body&gt;</pre>
<p><span id="more-471"></span></p>
<p>JS 代码是用来计算 CSS Expressions 的计算次数。</p>
<p>CSS Expressions 表达式代码：</p>
<pre class="prettyprint">
body {
	font-size:12px;
	font-family:Verdana;
	line-height:1.9
}
div a {
	display:block;
	border:1px solid #FF3366;
	width:expression(this.offsetWidth &gt; 750 ? test() : test());
}</pre>
<p><a href="http://www.17css.com/works/09/03/CSS%20Expressions1.html" title="可怕的CSS Expressions">查看Dome</a> （用 IE6/IE7 查看）</p>
<p>从上面的例子就可以明显的看到 CSS Expressions 的计算的如此的频繁，由此可见它的可怕。</p>
<p>子鼠还提供了一个稍好一点的写法：</p>
<pre class="prettyprint">
body {
	font-size:12px;
	font-family:Verdana;
	line-height:1.9
}
div a {
	display:block; border:1px solid #FF3366;
	width:expression(function(abc){
		abc.style.width = &quot;750px&quot;;
		test();
	}(this));
}</pre>
<p><a href="http://www.17css.com/works/09/03/CSS%20Expressions2.html" title="CSS Expressions">查看Dome</a> （用 IE6/IE7 查看）</p>
<p>另外 CSS Expressions 的兼容性很差，所以 CSS Expressions 能不用就不用。</p>
<p>&copy;2012 <a href="http://www.17css.com">一起CSS</a>. All Rights Reserved.</p>.<h2  class="related_post_title">随机日志</h2><ul class="related_post"><li><a href="http://www.17css.com/%e5%90%84%e7%9f%a5%e5%90%8d%e7%bd%91%e7%ab%99%e7%9a%84%e5%9b%a2%e9%98%9f%e5%8d%9a%e5%ae%a2%e3%80%81%e6%8b%9b%e8%81%98%e7%bd%91%e7%ab%99/" title="各知名网站的团队博客、招聘网站">各知名网站的团队博客、招聘网站</a> (0)</li><li><a href="http://www.17css.com/js-simulation-css-attribute-selectors/" title="用js模拟css属性选择器">用js模拟css属性选择器</a> (6)</li><li><a href="http://www.17css.com/%e8%a7%86%e9%a2%91%e6%95%99%e7%a8%8b/" title="视频教程">视频教程</a> (0)</li><li><a href="http://www.17css.com/css%e5%9b%be%e8%b1%a1%e6%9b%bf%e6%8d%a2%e6%8a%80%e6%9c%af%e4%b9%8bfahrner%e7%9a%84%e6%96%b9%e6%a1%88/" title="CSS图像替换技术之Fahrner的方案">CSS图像替换技术之Fahrner的方案</a> (0)</li><li><a href="http://www.17css.com/%e7%94%a8jquery%e5%8e%bb%e9%99%a4%e9%93%be%e6%8e%a5%e8%99%9a%e7%ba%bf/" title="用jQuery去除链接虚线">用jQuery去除链接虚线</a> (20)</li><li><a href="http://www.17css.com/the-new-user-interface-of-firefox4/" title="Mozilla Firefox 4.0最新用户界面">Mozilla Firefox 4.0最新用户界面</a> (7)</li><li><a href="http://www.17css.com/web%e6%a0%87%e5%87%86%e7%9a%84%e5%bc%80%e5%a7%8b%e2%80%94%e2%80%94doctype/" title="web标准的开始——DOCTYPE">web标准的开始——DOCTYPE</a> (0)</li><li><a href="http://www.17css.com/css%e5%9b%be%e8%b1%a1%e6%9b%bf%e6%8d%a2%e6%8a%80%e6%9c%af%e4%b9%8brundle%e7%9a%84%e6%96%b9%e6%a1%88/" title="CSS图像替换技术之Rundle的方案">CSS图像替换技术之Rundle的方案</a> (2)</li><li><a href="http://www.17css.com/2010-10-browser-market-share/" title="10月浏览器市场排行 Chrome增长快">10月浏览器市场排行 Chrome增长快</a> (1)</li><li><a href="http://www.17css.com/utf-8-include/" title="你从哪里来？——include上方的空格">你从哪里来？——include上方的空格</a> (2)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.17css.com/how-terrible-the-css-expressions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

