Last active
November 8, 2016 10:49
-
-
Save milosdjakonovic/f0617e85fd78f5db84a09a2a634a3b41 to your computer and use it in GitHub Desktop.
Dynamic css loader
This file contains 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
;(function(w,d){ | |
var head = d.head || d.getElementsByTagName('head')[0], | |
raf = w.requestAnimationFrame || | |
w.mozRequestAnimationFrame || | |
w.webkitRequestAnimationFrame || | |
w.msRequestAnimationFrame || | |
function(callback) { | |
return setTimeout(callback, 16) | |
}, | |
createAndAddLink = function(href){ | |
var link = d.createElement('link'); | |
link.rel="stylesheet"; | |
link.media="all"; | |
link.href = href; | |
raf(function(){ | |
head.appendChild(link); | |
}); | |
} | |
w.loadCss = function(){ | |
var args = arguments; | |
if(typeof args === 'string'){ | |
createAndAddLink(args); | |
return; | |
} | |
for(var i=0;i<args.length;i++){ | |
createAndAddLink(args[i]); | |
} | |
}; | |
})(window,document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment