Fireworks CS6 包括一个复制选定对象的 CSS3 属性的面板。
但是,代码过于冗长和混乱,所以我想用 JavaScript 编写一个扩展来清理它。
我已经完成了我需要的一切,除了弄清楚如何将任意数量的 rgb 值转换为它们更小的十六进制代码等价物。
例如,它为渐变返回的典型字符串可能包括:
background: -moz-linear-gradient(50% 0% -87deg, rgb(0,0,0) 0%, rgb(0,255,64) 28%, rgb(0,177,122) 40%, rgb(0,0,255) 68%, rgb(37,37,230) 76%, rgb(153,153,153) 100%);
background: -ms-linear-gradient(-87deg, rgb(0,0,0) 0%, rgb(0,255,64) 28%, rgb(0,177,122) 40%, rgb(0,0,255) 68%, rgb(37,37,230) 76%, rgb(153,153,153) 100%);
background: -o-linear-gradient(-87deg, rgb(0,0,0) 0%, rgb(0,255,64) 28%, rgb(0,177,122) 40%, rgb(0,0,255) 68%, rgb(37,37,230) 76%, rgb(153,153,153) 100%);
background: -webkit-gradient(linear,50% 0%,55% 100%, color-stop(0, rgb(0,0,0)), color-stop(0.28, rgb(0,255,64)), color-stop(0.4, rgb(0,177,122)), color-stop(0.68, rgb(0,0,255)), color-stop(0.76, rgb(37,37,230)), color-stop(1, rgb(153,153,153)));
background: -webkit-linear-gradient(-87deg, rgb(0,0,0) 0%, rgb(0,255,64) 28%, rgb(0,177,122) 40%, rgb(0,0,255) 68%, rgb(37,37,230) 76%, rgb(153,153,153) 100%);
background: linear-gradient(-87deg, rgb(0,0,0) 0%, rgb(0,255,64) 28%, rgb(0,177,122) 40%, rgb(0,0,255) 68%, rgb(37,37,230) 76%, rgb(153,153,153) 100%);
border-color: rgb(198,34,221);
我已经有一个函数可以将 r,g,b 值转换为等效的十六进制值,但是我不确定如何循环遍历字符串并隔离 rgb 组件并转换每个组件。