颜色color转为rgb格式

function convertHexToRGB(color) {
      if (color.length === 4) {
            let extendedColor = "#"
            for (let i = 1; i < color.length; i++) {
                 extendedColor += color.charAt(i) + color.charAt(i)
             }
            color = extendedColor
       }
       const values = {
             r: parseInt(color.substr(1, 2), 16),
            g: parseInt(color.substr(3, 2), 16),
            b: parseInt(color.substr(5, 2), 16),
           }
         return `${values.r}, ${values.g}, ${values.b}`
}
 
backgroundColor: `rgba(${convertHexToRGB(color)},0.2)`
原文地址:https://www.cnblogs.com/cnlg123/p/11187913.html