作者的文章

Chris Coyier

创始人、作家、设计师、垃圾邮件删除者、邮件个性

直接链接到文章 突破 iframe

突破 iframe

if (top.location!= self.location) {
   top.location = self.location.href;
}

这通常可以工作,但在 window 被覆盖的情况下,可能存在很小的失败可能性。以下是来自 Nathan Smith 的几个巧妙的替代方案

<script>

// Break 
直接链接到文章 addClass 函数

addClass 函数

如果您不使用库,则可能需要像这样自己编写函数。

function addClass(id,new_class){
       var i,n=0;

       new_class=new_class.split(",");

       for(i=0;i<new_class.length;i++){
               if((" "+document.getElementById(id).className+" ").indexOf(" "+new_class[i]+" ")==-1){
                       document.getElementById(id).className+=" "+new_class[i];
                       n++;
               }
       }

       return n;
}

用法

<div id="changeme" class="big red"></div>
<button 
直接链接到文章 CSS 分析和优化

CSS 分析和优化

就在我刚说完我希望我们很快就能停止谈论 CSS 选择器性能时,Juriy Zaytsev 发布了一些关于使用 Opera 和 WebKit 的新“样式分析器”作为开发工具的一部分进行选择器性能研究的精彩研究。…