Giter Site home page Giter Site logo

wangxb07 / rem-unit-polyfill Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chuckcarpenter/rem-unit-polyfill

0.0 2.0 0.0 724 KB

A polyfill to parse CSS links and rewrite pixel equivalents into head for non supporting browsers

Home Page: http://chuckcarpenter.github.io/REM-unit-polyfill/

License: MIT License

CoffeeScript 12.25% CSS 11.32% HTML 9.02% JavaScript 67.42%

rem-unit-polyfill's Introduction

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.

rem-unit-polyfill's People

Contributors

chuckcarpenter avatar squat avatar alray avatar danreynolds avatar dfurnes avatar ny0m avatar asakurayoh avatar ajb avatar calinou avatar chrishouse avatar muchabi avatar redknight91 avatar dvorapa avatar hitautodestruct avatar

Watchers

James Cloos avatar wangxb07 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.