-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdcss.js
30 lines (27 loc) · 799 Bytes
/
dcss.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Return sheet object
// Paramenter: media (string)
// + media query
// + Ex: "only screen and (max-width : 1024px)"
function DynamicCss(media) {
// Create the <style> tag
var style = document.createElement("style");
if (typeof media === "string") {
style.setAttribute("media", media);
}
// WebKit hacks
style.appendChild(document.createTextNode(""));
// Add the <style> element to the page
document.head.appendChild(style);
function addCSSRule(sheet, selector, rules, index) {
if("insertRule" in sheet) {
sheet.insertRule(selector + "{" + rules + "}", index);
}
else if("addRule" in sheet) {
sheet.addRule(selector, rules, index);
}
}
style.sheet.addRule = function(selector, rules) {
return addCSSRule(style.sheet, selector, rules);
}
return style.sheet;
})();