Created
August 24, 2015 08:47
-
-
Save dented/e3903ff0ce1a29b3f0ab to your computer and use it in GitHub Desktop.
Efficiently insert styles to page, instead of inlining each element which is more expensive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var sheet = (function() { | |
| // Create the <style> tag | |
| var style = document.createElement('style'); | |
| // Add a media (and/or media query) here if you'd like! | |
| // style.setAttribute('media', 'screen') | |
| // style.setAttribute('media', 'only screen and (max-width : 1024px)') | |
| // WebKit hack :( | |
| style.appendChild(document.createTextNode('')); | |
| // Add the <style> element to the page | |
| document.head.appendChild(style); | |
| return style.sheet; | |
| })(); | |
| // Usage | |
| sheet.insertRule("header { float: left; opacity: 0.8; }", 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment