* @function StyleUtils.hexToRgba * @description 十六进制转 RGBA 格式。 * @param {Object} hex - 十六进制格式参数。 * @param {number} opacity -Alpha 参数。 * @returns {string} 生成的 RGBA 格式。
(hex, opacity)
| 556 | * @returns {string} 生成的 RGBA 格式。 |
| 557 | */ |
| 558 | static hexToRgba(hex, opacity) { |
| 559 | var color = [], rgba = []; |
| 560 | hex = hex.replace(/#/, ""); |
| 561 | if (hex.length == 3) { |
| 562 | var tmp = []; |
| 563 | for (let i = 0; i < 3; i++) { |
| 564 | tmp.push(hex.charAt(i) + hex.charAt(i)); |
| 565 | } |
| 566 | hex = tmp.join(""); |
| 567 | } |
| 568 | for (let i = 0; i < 6; i += 2) { |
| 569 | color[i] = "0x" + hex.substr(i, 2); |
| 570 | rgba.push(parseInt(Number(color[i]))); |
| 571 | } |
| 572 | rgba.push(opacity); |
| 573 | return "rgba(" + rgba.join(",") + ")"; |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * @function StyleUtils.getDefaultStyle |
no test coverage detected