简介
偶尔需要转换颜色格式,然后使用。如rgb和十六进制之间的互相转换
具体实现
使用:
import { TzColorExchangeStyle } from colorExchange.js
console.log(TzColorExchangeStyle.formatColorFun('#ffffff'))
// colorExchange.js
class TzColorExchangeStyle {
static get reg() {
return /^#([0-9a-fA-f]{
3}|[0-9a-fA-f]{
6})$/
}
static get regTwo() {
return /^0x([0-9a-fA-f]{
3}|[0-9a-fA-f]{
6})$/
}
// rgb转换为 #?????? 的16进制,或补全#fff为#ffffff
static rgbToHexadecimalNormal(value) {
// 如果是rgb颜色表示
if (/^(rgb|RGB)/.test(value)) {
let aColor = value.replace(/(?:\(|\)|rgb|RGB)*/g, '').split(',')
let strHex =