Created
February 2, 2015 04:00
-
-
Save zoxon/5f15193fd9b29390b3b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Преобразует 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