Skip to content

Instantly share code, notes, and snippets.

@zoxon
Created February 2, 2015 04:00
Show Gist options
  • Save zoxon/5f15193fd9b29390b3b4 to your computer and use it in GitHub Desktop.
Save zoxon/5f15193fd9b29390b3b4 to your computer and use it in GitHub Desktop.
/**
* Преобразует HEX-представление цвета в RGB.
* @param {String} hex
* @return {Array}
*/
var hex2Rgb = function(hex) {
if ('#' == hex.substr(0, 1)) {
hex = hex.substr(1);
}
if (3 == hex.length) {
hex = hex.substr(0, 1) + hex.substr(0, 1) + hex.substr(1, 1) + hex.substr(1, 1) + hex.substr(2, 1) + hex.substr(2, 1);
}
return [parseInt(hex.substr(0, 2), 16), parseInt(hex.substr(2, 2), 16), parseInt(hex.substr(4, 2), 16)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment