Skip to content

Instantly share code, notes, and snippets.

@xwartz
Created September 14, 2015 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xwartz/87298970b543e4ac128d to your computer and use it in GitHub Desktop.
Save xwartz/87298970b543e4ac128d to your computer and use it in GitHub Desktop.
颜色从十六进制转为 rgba
// 颜色 从十六进制转为 rgba
exports.convertHex = function(hex, opacity) {
hex = hex.replace('#', '');
r = parseInt(hex.substring(0, 2), 16);
g = parseInt(hex.substring(2, 4), 16);
b = parseInt(hex.substring(4, 6), 16);
result = 'rgba(' + r + ',' + g + ',' + b + ',' + opacity / 100 + ')';
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment