parse css gradient rule with Javascript regex

前端 未结 3 1981
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 12:23

in my css file I have gradient rule, like this:

background-image:linear-gradient(to right, #FF0000 0%, #00FF00 20px, rgb(0, 0, 255) 100%);

3条回答
  •  甜味超标
    2021-01-18 13:05

    Thanks for sharing some great time saving code. I noticed an error on the following line, which doesn't allow decimal opacity:

    rDigits4 = /(\s*(?:[0-9]{1,3}\s*,\s*){3}[0-9]{1,3}\s*)/,// "(1, 2, 3, 4)"

    I recommend using this instead, which also supports decimal values with more than 3 numbers:

    rDigits4 = /(\s*(?:[0-9]{1,3}\s*,\s*){3}(?:[.\d]+)\s*)/,// "(1, 2, 3, .4)"

提交回复
热议问题