Nov 14, 2012 - 前端    No Comments

Use Modernizr

modernizr.js是一个可以帮组前端了解浏览器特性,并写出渐进式增强css的js文件。
使用起来非常简单,首先在html的head区加入代码:

<script src="js/modernizr-2.6.2.min.js"></script>

这段代码一定要加在head关门标签前,而不能放在body关门标签前。

然后给html标签加上一个class

<html class="no-js">

其实这个class加不加都可以的,但如果真的碰到不能运行js的浏览器这个class就可以起作用了。

然后在浏览器里打开这个页面,可以看到:

然后就可以根据html标签上的class写出渐进增强的css了

body {
    background: url(background-one.png) top left repeat-x;
}
.multiplebgs body {
    background: url(background-one.png) top left repeat-x,
    url(background-two.png) bottom left repeat-x;
}

Got anything to say? Go ahead and leave a comment!