<?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, 27 Jul 2010 00:58:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</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;2010 <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/%e6%88%91%e7%9c%8b%e8%b6%85%e8%bf%87%e9%83%a8%e5%88%86%e8%87%aa%e5%8a%a8%e9%9a%90%e8%97%8f%e6%88%96%e6%98%be%e7%a4%ba%e7%9c%81%e7%95%a5%e5%8f%b7/" title="我看超过部分自动隐藏或显示省略号">我看超过部分自动隐藏或显示省略号</a> (4)</li><li><a href="http://www.17css.com/%e4%bd%a0%e6%98%af%e4%b8%80%e4%b8%aa%e8%81%8c%e4%b8%9a%e7%9a%84%e9%a1%b5%e9%9d%a2%e9%87%8d%e6%9e%84%e5%b7%a5%e4%bd%9c%e8%80%85%e5%90%97%ef%bc%9f/" title="你是一个职业的页面重构工作者吗？">你是一个职业的页面重构工作者吗？</a> (5)</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/june-2010-ie-browser-market-share-of-global-back-more-than-60-percent/" title="IE全球市占率重新超过60%">IE全球市占率重新超过60%</a> (0)</li><li><a href="http://www.17css.com/%e4%b8%8a%e4%b8%8b%e4%b8%a4%e5%bc%a0%e5%9b%be%e7%89%87css%e5%9c%86%e8%a7%92/" title="上下两张图片CSS圆角">上下两张图片CSS圆角</a> (0)</li><li><a href="http://www.17css.com/%e7%9c%9f%e6%ad%a3%e7%9a%84css%e7%ad%89%e9%ab%98%e5%b8%83%e5%b1%80/" title="真正的CSS等高布局">真正的CSS等高布局</a> (6)</li><li><a href="http://www.17css.com/the-distinction-between-strong-and-em/" title="HTML标签strong和em的区别">HTML标签strong和em的区别</a> (3)</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%8blevin%e7%9a%84%e6%96%b9%e6%a1%88/" title="CSS图像替换技术之Levin的方案">CSS图像替换技术之Levin的方案</a> (2)</li><li><a href="http://www.17css.com/divcss%e7%bd%91%e9%a1%b5%e8%ae%be%e8%ae%a1%e8%a7%86%e9%a2%91%e6%95%99%e7%a8%8b/" title="DIV+CSS网页设计视频教程">DIV+CSS网页设计视频教程</a> (5)</li><li><a href="http://www.17css.com/ie6%e4%b8%8bimportant%e7%9a%84bug/" title="IE6下!important的bug">IE6下!important的bug</a> (1)</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>
