BoltClock , jQuery CSS, 3.2.0.
- , jQuery $.fn.css .
, , , Custom (, ). , JS, $.fn.css.
(function() {
var originalFnCss = $.fn.css;
$.fn.css = function(prop, val) {
if (prop.indexOf("--") === 0) {
if(val) {
for(var idx = 0; idx < this.length; idx++) {
this[idx].style.setProperty(prop, val);
}
} else {
return window.getComputedStyle(this[0]).getPropertyValue(prop);
}
} else {
return originalFnCss.apply(this, arguments);
}
};
}());
. jQuery 1.11.1, 2.2.4 3.1.1, , - , - .
jQuery $.fn.css. :
(function() {
var originalFnCss = $.fn.css;
$.fn.css = function(prop, val) {
if (prop.indexOf("--") === 0) {
if(val) {
for(var idx = 0; idx < this.length; idx++) {
this[idx].style.setProperty(prop, val);
}
} else {
return window.getComputedStyle(this[0]).getPropertyValue(prop);
}
} else {
return originalFnCss.apply(this, arguments);
}
};
}());
$(":root").css("--color1", "red");
console.log(".css method on ":root" :", $(":root").css("--color1"));
$(":root")[0].style.setProperty("--color2", "lime");
console.log("[0].style method on ":root" :", $(":root")[0].style.getPropertyValue('--color2'));
#p1 {
background-color: var(--color1);
}
#p2 {
background-color: var(--color2);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<body id="bodyID">
<p id="p1">p with background --color1</p>
<p id="p2">p with background --color2</p>
</body>
<html>