chuckcarpenter/REM-unit-polyfill
Fork: 211 Star: 721 (更新于 2024-10-31 07:16:55)
license: MIT
Language: JavaScript .
A polyfill to parse CSS links and rewrite pixel equivalents into head for non supporting browsers
最后发布版本: 1.3.4 ( 2015-05-06 23:52:43)
REM unit polyfill
No fluff here. The polyfill will test any browser for REM support and patch it up if needed, although we all know IE8 and below is where the issue lies. Once lack of support is determined, it reads all the link tags for stylesheets and finds selectors that have rules using the REM unit. It then recalculates those rules to PX and writes them in the head to override in the cascade. Magic.
Special shout out to Lucas Serven for the first version and all the amazing RegEx that's gone into this.
It has been tested on a large production publishing site and works great with minor performance differences.
We're always open to suggestions and/or improvements, so please fork!
Getting Started
Using rem.js is a cinch; you can load the polyfill conditionally using a loader like yepnope or simply by including a reference to it in your page like so: <script src="js/rem.js" type="text/javascript"></script>
. As a best practice, you should either reference rem.js after all of your stylesheets or, better yet, at the end of your <body>
tag.
In some cases you may want the polyfill to skip some stylesheets; if that's you then just add data-norem
as an attribute to the link tags of the stylesheets to be ignored. There are a few reasons you may want to do this: if you are loading a crazy long stylesheet that you know doesn't use REM units, then having the polyfill skip it will give your page a moderate speed boost and will help avoid a Flash of Unstyled Content; and if your page loads CSS from another domain that doesn't have CORS enabled then you should tell the polyfill to ignore that CSS since it will not be able to load the stylesheet.
This repo includes a small example so you can bring up the polyfill in your browser to see how it works.
Install using Bower
bower install REM-unit-polyfill
License
This content is released under the MIT License.
最近版本更新:(数据更新于 2024-10-03 14:39:51)
2015-05-06 23:52:43 1.3.4
2015-04-21 03:12:21 v1.3.3
2014-07-03 04:02:18 v1.3.2
2014-07-01 06:30:13 v1.3.1
2014-06-22 06:31:25 v1.3.0
2014-06-06 23:15:38 v1.2.5
2014-05-21 07:59:31 v1.2.4
2014-03-31 01:03:30 v1.2.2
2014-03-31 00:41:36 v1.2.1
2013-12-12 06:30:44 v1.1.0
chuckcarpenter/REM-unit-polyfill同语言 JavaScript最近更新仓库
2024-11-13 00:07:54 bia-pain-bache/BPB-Worker-Panel
2024-11-12 11:08:54 emberjs/ember.js
2024-11-12 04:44:31 nodejs/node
2024-11-11 12:06:37 gethomepage/homepage
2024-11-10 21:29:01 Number178/kikoeru-express
2024-11-09 19:30:14 vernesong/OpenClash