十六进制颜色码转换成RGB颜色值
Posted LikWin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了十六进制颜色码转换成RGB颜色值相关的知识,希望对你有一定的参考价值。
;(function (name, context, factory) {
// Supports UMD. AMD, CommonJS/Node.js and browser context
if (typeof module !== "undefined" && module.exports) {
module.exports = factory();
} else if (typeof define === "function" && define.amd) {
define(factory);
} else {
context[name] = factory();
}
})(‘LikWin‘, window, function () {
‘use strict‘;
var LikWin = {
getRGBA: function (hex) {
var rgb = [0, 0, 0, a];
if (/#(..)(..)(..)/g.test(hex)) {
rgb = [parseInt(RegExp.$1, 16), parseInt(RegExp.$2, 16), parseInt(RegExp.$3, 16)];
};
return "rgb(" + rgb.join(",") + ")";
},
getRGBA: function (hex, a) {
var rgb = [0, 0, 0, a];
if (/#(..)(..)(..)/g.test(hex)) {
rgb = [parseInt(RegExp.$1, 16), parseInt(RegExp.$2, 16), parseInt(RegExp.$3, 16)];
};
return "rgba(" + rgb.join(",") + ", " + a + ")";
}
};
return LikWin;
});
以上是关于十六进制颜色码转换成RGB颜色值的主要内容,如果未能解决你的问题,请参考以下文章
JavaScript之颜色值相互转换十六进制正则rgbtoStringslicetoUpperCasesplitfiltermapparseInt
JavaScript之颜色值相互转换十六进制正则rgbtoStringslicetoUpperCasesplitfiltermapparseInt