helpers.js 576 B

12345678910111213
  1. function hexToRgb(hexCode) {
  2. var patt = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/;
  3. var matches = patt.exec(hexCode);
  4. var rgb = "rgb(" + parseInt(matches[1], 16) + "," + parseInt(matches[2], 16) + "," + parseInt(matches[3], 16) + ")";
  5. return rgb;
  6. }
  7. function hexToRgba(hexCode, opacity) {
  8. var patt = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/;
  9. var matches = patt.exec(hexCode);
  10. var rgb = "rgba(" + parseInt(matches[1], 16) + "," + parseInt(matches[2], 16) + "," + parseInt(matches[3], 16) + "," + opacity + ")";
  11. return rgb;
  12. }