Last active
August 29, 2015 14:03
-
-
Save simevidas/cd4c5af291dec41a816f to your computer and use it in GitHub Desktop.
color parsing API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Tab Atkins's color parsing API proposal | |
* Source: http://www.w3.org/blog/CSS/2014/07/10/minutes-telecon-219/ | |
*/ | |
var color; | |
// creating color objects from RGBA components | |
color = RGBAColor(50, 100, 150, .5); | |
color = RGBAColor({ r: 50, g: 100, b: 150, a: .5 }); | |
// creating color objects from HSLA components | |
color = RGBAColor.fromHSLA(100, .3, .4, .5); | |
color = RGBAColor.fromHSLA({ h: 100, s: .3, l: .4, a: .5 }); | |
// creating color objects from HEX values | |
// Q: Not sure how HEX values are different from RGBA values | |
// properties/methods of color objects | |
color.r | |
color.g | |
color.b | |
color.a | |
color.asHSL() // returns { h, s, l, a } object | |
color.asHex() // returns { r, g, b, a } object | |
color.asName() | |
color.toString() | |
// parsing any CSS color | |
color = CSS.parseColor('#FAA'); | |
color = CSS.parseColor('rgb(100,150,200)'); | |
color = CSS.parseColor('orangered'); | |
// color objects can be assigned directly to CSS properties | |
document.body.style.backgroundColor = color; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment