1234567891011121314151617181920 |
- /*
- * @Description: rgb值转换hex
- * @Autor: kindring
- * @Date: 2021-11-16 11:21:02
- * @LastEditors: kindring
- * @LastEditTime: 2022-01-06 11:38:33
- * @LastDescript:
- */
- let rgb = 'rgb(244,246,244)'
- function rgbToHex(str) {
- return str.replace(/(rgb\(|\))/g, '').split(',').reduce((a, c) => {
- c = parseInt(c).toString(16)
- return a + `${ c.length<2?'0'+c:c}`
- }, '#')
- }
- console.log(rgbToHex(rgb));
|