<?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>某人的栖息地 &#187; css</title>
	<atom:link href="http://www.ooso.net/tag/css/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ooso.net</link>
	<description>Linux + Apache + Mysql + Php + Flash</description>
	<lastBuildDate>Thu, 19 Jan 2012 01:21:44 +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>yepnope.js &#8211; 异步加载资源文件</title>
		<link>http://www.ooso.net/archives/591</link>
		<comments>http://www.ooso.net/archives/591#comments</comments>
		<pubDate>Tue, 08 Mar 2011 05:29:47 +0000</pubDate>
		<dc:creator>Volcano</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[yepnope]]></category>

		<guid isPermaLink="false">http://www.ooso.net/?p=591</guid>
		<description><![CDATA[yepnope.js是一个能够根据输入条件来选择性异步加载资源文件的js脚本，可以在页面上仅加载用户需要的js/css。
典型代码示例
yepnope({
  test : Modernizr.geolocation,

				<span class="readmore"><a href="http://www.ooso.net/archives/591" title="yepnope.js &#8211; 异步加载资源文件">阅读全文（1006字）</a></span>]]></description>
			<content:encoded><![CDATA[<p><a href="http://yepnopejs.com/">yepnope.js</a>是一个能够根据输入条件来选择性异步加载资源文件的js脚本，可以在页面上仅加载用户需要的js/css。</p>
<h2>典型代码示例</h2>
<pre><code>yepnope({
  test : Modernizr.geolocation,
  yep  : 'normal.js',
  nope : ['polyfill.js', 'wrapper.js']
});</code></pre>
<p>当Modernizr.geolocation为真时，加载yep项也就是&#8221;normal.js&#8221;，否则加载nope项——可以同时加载多个文件。</p>
<h2>yepnope和现有的xxx script loader有什么区别？</h2>
<p>个人认为主要 是这两点：</p>
<ul>
<li>可以同时处理javascript以及css</li>
<li>能够按条件加载</li>
</ul>
<h2>yepnope的全部参数</h2>
<pre><code>yepnope([{
  test : /* boolean(ish) - 你要检查真伪的表达式             */,
  yep  : /* array (of strings) | string - test为true时加载这项  */,
  nope : /* array (of strings) | string - test为false时加载这项 */,
  both : /* array (of strings) | string - 什么情况下都加载              */,
  load : /* array (of strings) | string - 什么情况下都加载              */,
  callback : /* function ( testResult, key ) | object { key : fn }   当某个url加载成功时执行相应的方法         */,
  complete : /* function   都加载完成了执行这个方法                                                   */
}, ... ]);</code></pre>
<p>这里的参数都可以是array或者object，在加载多个资源文件的时候有用。</p>
<h3>yepnope加载jquery的实例</h3>
<pre><code>yepnope([{
  load: 'http:/­/ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js',
  complete: function () {
    if (!window.jQuery) {
      yepnope('local/jquery.min.js');
    }
  }
}, {
  load: 'jquery.plugin.js',
  complete: function () {
    jQuery(function () {
      jQuery('div').plugin();
    });
  }
}]);</code></pre>
<p>这段代码异步加载了jquery和jquery.plugin.js，甚至还对jquery加载失败的情况做了一个备用处理。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ooso.net/archives/591/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>推荐一下Firefox插件Stylish</title>
		<link>http://www.ooso.net/archives/408</link>
		<comments>http://www.ooso.net/archives/408#comments</comments>
		<pubDate>Sun, 01 Jun 2008 23:29:05 +0000</pubDate>
		<dc:creator>Volcano</dc:creator>
				<category><![CDATA[firefox]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[新浪]]></category>

		<guid isPermaLink="false">http://www.ooso.net/?p=408</guid>
		<description><![CDATA[Stylish是这样一个firefox插件，你可以利用它来定制目标网页或网站的css样式，甚至一些firefox app的样式，让浏览效果更加舒适。而且在UserStyles网站上已经有不少现成的样式可供下载，让不会写css的普通用户也可以享受到它的便利。
其实Stylish和greasemonkey正好是一对，一个改变css，一个改变javascript。之前我写了一个用来看新浪新闻的greasemonkey脚本，这个脚本的大概原理是删除了新浪新闻页面上的右侧边栏，这样浏览的范围会更加宽一些，但是greasemonkey脚本会有这样一个缺点，它必须等到页面load完成之后，才开始生效，这样看上去会比较突兀，洋人对这个等待load的时间有个专有名词——flicker（这个词可不是指的图片网站flickr哦）。

				<span class="readmore"><a href="http://www.ooso.net/archives/408" title="推荐一下Firefox插件Stylish">阅读全文（968字）</a></span>]]></description>
			<content:encoded><![CDATA[<p><a href="https://addons.mozilla.org/en-US/firefox/addon/2108">Stylish</a>是这样一个firefox插件，你可以利用它来定制目标网页或网站的css样式，甚至一些firefox app的样式，让浏览效果更加舒适。而且在<a href="http://userstyles.org/">UserStyles</a>网站上已经有不少现成的样式可供下载，让不会写css的普通用户也可以享受到它的便利。</p>
<p>其实Stylish和greasemonkey正好是一对，一个改变css，一个改变javascript。之前我写了一个<a href="http://www.ooso.net/index.php/archives/302">用来看新浪新闻的greasemonkey脚本</a>，这个脚本的大概原理是删除了新浪新闻页面上的右侧边栏，这样浏览的范围会更加宽一些，但是greasemonkey脚本会有这样一个缺点，它必须等到页面load完成之后，才开始生效，这样看上去会比较突兀，洋人对这个等待load的时间有个专有名词——flicker（这个词可不是指的图片网站flickr哦）。</p>
<p>使用Stylish就可以有效避免flicker，它在页面最开始载入时就是生效的，也不会有greasemonkey产生的突兀效果了。比如我用来看新浪新闻的样式是这样的:</p>
<pre><code>@namespace url(http://www.w3.org/1999/xhtml);

@-moz-document url-prefix("http://news.sina.com.cn/") {
td.lc_blue {width:100%!important; font-size:1.2em;}
div.rightShell {display:none}
}</code></pre>
<p>这个css除了把侧边广告隐藏以外，还把新闻的字体调大，像我这样的近视眼就可以看的比较轻松了。其中的<a href="http://developer.mozilla.org/en/docs/CSS:%40-moz-document">-moz-document</a>关键字是消除flicker的关键：</p>
<blockquote><p>The @-moz-document rule is a Gecko-specific at-rule that restricts the style rules contained within it based on the URL of the document. It is designed primarily for user style sheets.</p></blockquote>
<p>所以要想写出避免flicker发生的greasemonkey脚本，最好是加上Stylish支持，用<b>-moz-document()</b>来隐藏会变化的html部分，待到页面载入完成之后，greasemonkey脚本就可以不慌不忙的处理后续事宜了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ooso.net/archives/408/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>在页面中动态载入外部javascript</title>
		<link>http://www.ooso.net/archives/312</link>
		<comments>http://www.ooso.net/archives/312#comments</comments>
		<pubDate>Tue, 12 Jun 2007 15:03:40 +0000</pubDate>
		<dc:creator>Volcano</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.ooso.net/index.php/archives/312</guid>
		<description><![CDATA[有时候需要在网页中某个div载入之后，动态引入一段javascript，IE下的解决方案：
newjs.onreadystatechange = function () {
        if (newjs.readyState == 'loaded') {
            // ready!

				<span class="readmore"><a href="http://www.ooso.net/archives/312" title="在页面中动态载入外部javascript">阅读全文（1118字）</a></span>]]></description>
			<content:encoded><![CDATA[<p>有时候需要在网页中某个div载入之后，动态引入一段<a href="index.php?tag=javascript">javascript</a>，IE下的解决方案：</p>
<pre><code>newjs.onreadystatechange = function () {
        if (newjs.readyState == 'loaded') {
            // ready!
        }
    }

    newjs.onload = function () {
        // ready!
    }</code></pre>
<p>主要利用了onload以及onreadystatechange事件。把这个加以利用，也能动态载入外部css。下面是同时适合Ie/<a href="http://firefox.viewc.com">firefox</a>的写法。</p>
<p><span id="more-312"></span></p>
<pre><code>var css;
function include_css(css_file) {
    var html_doc = document.getElementsByTagName('head')[0];
    css = document.createElement('link');
    css.setAttribute('rel', 'stylesheet');
    css.setAttribute('type', 'text/css');
    css.setAttribute('href', css_file);
    html_doc.appendChild(css);

    // alert state change
    css.onreadystatechange = function () {
        if (css.readyState == 'complete') {
            alert('CSS onreadystatechange fired');
        }
    }
    css.onload = function () {
        alert('CSS onload fired');
    }
    return false;
}

var js;
function include_js(file) {
    var html_doc = document.getElementsByTagName('head')[0];
    js = document.createElement('script');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', file);
    html_doc.appendChild(js);

    js.onreadystatechange = function () {
        if (js.readyState == 'complete') {
            alert('JS onreadystate fired');
        }
    }

    js.onload = function () {
        alert('JS onload fired');
    }
    return false;
}</code></pre>
<p>这里是<a href="http://www.phpied.com/files/jinc/test_ready_onload.html">Demo</a>，有动态载入css以及js的例子。</p>
<h1>原文地址</h1>
<p><a href="http://www.phpied.com/javascript-include-ready-onload/">http://www.phpied.com/javascript-include-ready-onload/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ooso.net/archives/312/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

