Files
sx-fc/app/assets/javascripts/BSBMaterial/helpers.js
2017-10-23 11:38:10 +06:30

13 lines
576 B
JavaScript
Executable File

function hexToRgb(hexCode) {
var patt = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/;
var matches = patt.exec(hexCode);
var rgb = "rgb(" + parseInt(matches[1], 16) + "," + parseInt(matches[2], 16) + "," + parseInt(matches[3], 16) + ")";
return rgb;
}
function hexToRgba(hexCode, opacity) {
var patt = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/;
var matches = patt.exec(hexCode);
var rgb = "rgba(" + parseInt(matches[1], 16) + "," + parseInt(matches[2], 16) + "," + parseInt(matches[3], 16) + "," + opacity + ")";
return rgb;
}