Snap.getRGB(color)
优质
小牛编辑
135浏览
2023-12-01
Parses color string as RGB object
Parameters
- colorstringcolor string in one of the followingformats:
- Color name (
red
,green
,cornflowerblue
, etc) - #••• — shortened HTML color: (
#000
,#fc0
, etc.) - #•••••• — full length HTML color: (
#000000
,#bd2300
) - rgb(•••, •••, •••) — red, green and blue channelsvalues: (
rgb(200, 100, 0)
) - rgba(•••, •••, •••, •••) — also with opacity
- rgb(•••%, •••%, •••%) — same as above, but in%: (
rgb(100%, 175%, 0%)
) - rgba(•••%, •••%, •••%, •••%) — also with opacity
- hsb(•••, •••, •••) — hue, saturation and brightnessvalues: (
hsb(0.5, 0.25, 1)
) - hsba(•••, •••, •••, •••) — also with opacity
- hsb(•••%, •••%, •••%) — same as above, but in%
- hsba(•••%, •••%, •••%, •••%) — also with opacity
- hsl(•••, •••, •••) — hue, saturation and luminosityvalues: (
hsb(0.5, 0.25, 0.5)
) - hsla(•••, •••, •••, •••) — also with opacity
- hsl(•••%, •••%, •••%) — same as above, but in%
- hsla(•••%, •••%, •••%, •••%) — also with opacity
Note that %
can be used any time: rgb(20%, 255, 50%)
.
Returns: object RGB object in the following format:
- {
- r numberred,
- g numbergreen,
- b numberblue,
- hex stringcolor in HTML/CSS format: #••••••,
- error booleantrue if string can't be parsed
- }