Takes a named string, hex string, array of rgb or rgba values, an object with r, g, b, and a properties, or another Color
object and creates a new Color instance to work from.
(color);
Parameter | Type | Description |
---|---|---|
color | Array | String | Object |
See the dojo/_base/Color reference documentation for more information.
Work with a Color instance:
require(["dojo/_base/color"], function(Color){
var c = new Color();
c.setColor([0,0,0]); // black
var hex = c.toHex(); // #000000
});
Work with a node's color:
require(["dojo/_base/color", "dojo/dom-style"], function(Color, domStyle){
var color = domStyle("someNode", "backgroundColor");
var n = new Color(color);
// adjust the color some
n.r *= .5;
console.log(n.toString()); // rgb(128, 255, 255);
});
Defined by: dojo/_base/Color
Defined by: dojo/_base/Color
Defined by: dojo/_base/Color
Defined by: dojo/_base/Color
Dictionary list of all CSS named colors, by name. Values are 3-item arrays with corresponding RG and B values.
Defined by: dojo/_base/Color
blendColors
(start,end,weight,obj)
Defined by dojo/_base/Color
Blend colors end and start with weight from 0 to 1, 0.5 being a 50/50 blend, can reuse a previously allocated Color object for the result
Parameter | Type | Description |
---|---|---|
start | dojo/_base/Color | |
end | dojo/_base/Color | |
weight | Number | |
obj | dojo/_base/Color | Optional |
Returns: undefined
fromArray
(a,obj)
Defined by dojo/_base/Color
Builds a Color
from a 3 or 4 element array, mapping each element in sequence to the rgb(a) values of the color.
Parameter | Type | Description |
---|---|---|
a | Array | |
obj | dojo/_base/Color | Optional |
Returns: any | undefined
A Color object. If obj is passed, it will be the return value.
require(["dojo/_base/color"], function(Color){
var myColor = new Color().fromArray([237,237,237,0.5]); // grey, 50% alpha
});
fromHex
(color,obj)
Defined by dojo/_base/Color
Converts a hex string with a '#' prefix to a color object. Supports 12-bit #rgb shorthand. Optionally accepts a Color
object to update with the parsed value.
Parameter | Type | Description |
---|---|---|
color | String | |
obj | dojo/_base/Color | Optional |
Returns: any
A Color object. If obj is passed, it will be the return value.
require(["dojo/_base/color"], function(Color){
var thing = new Color().fromHex("#ededed"); // grey, longhand
var thing2 = new Color().fromHex("#000"); // black, shorthand
});
fromRgb
(color,obj)
Defined by dojo/colors
get rgb(a) array from css-style color declarations
this function can handle all 4 CSS3 Color Module formats: rgb, rgba, hsl, hsla, including rgb(a) with percentage values.
Parameter | Type | Description |
---|---|---|
color | String | |
obj | dojo/_base/Color | Optional |
Returns: null
fromString
(str,obj)
Defined by dojo/_base/Color
Parses str
for a color value. Accepts hex, rgb, and rgba style color values.
Acceptable input values for str may include arrays of any form accepted by dojo.colorFromArray, hex strings such as "#aaaaaa", or rgb or rgba strings such as "rgb(133, 200, 16)" or "rgba(10, 10, 10, 50)"
Parameter | Type | Description |
---|---|---|
str | String | |
obj | dojo/_base/Color | Optional |
Returns: any
A Color object. If obj is passed, it will be the return value.
makeGrey
(g,a)
Defined by dojo/colors
creates a greyscale color with an optional alpha
Parameter | Type | Description |
---|---|---|
g | Number | |
a | Number | Optional |
sanitize
()
Defined by dojo/colors
makes sure that the object has correct attributes
setColor
(color)
Defined by dojo/_base/Color
Takes a named string, hex string, array of rgb or rgba values, an object with r, g, b, and a properties, or another Color
object and sets this color instance to that value.
Parameter | Type | Description |
---|---|---|
color | Array | String | Object |
Returns: function
Takes a named string, hex string, array of rgb or rgba values, an object with r, g, b, and a properties, or another Color
object and sets this color instance to that value.
require(["dojo/_base/color"], function(Color){
var c = new Color(); // no color
c.setColor("#ededed"); // greyish
});
toCmy
()
Defined by dojox/color/_base
Convert this Color to a CMY definition.
Returns: object
toCmyk
()
Defined by dojox/color/_base
Convert this Color to a CMYK definition.
Returns: object
toCss
(includeAlpha)
Defined by dojo/_base/Color
Returns a css color string in rgb(a) representation
Parameter | Type | Description |
---|---|---|
includeAlpha | Boolean | Optional |
Returns: string
require(["dojo/_base/color"], function(Color){
var c = new Color("#FFF").toCss();
console.log(c); // rgb('255','255','255')
});
toHex
()
Defined by dojo/_base/Color
Returns a CSS color string in hexadecimal representation
Returns: string
require(["dojo/_base/color"], function(Color){
console.log(new Color([0,0,0]).toHex()); // #000000
});
toHsl
()
Defined by dojox/color/_base
Convert this Color to an HSL definition.
Returns: object
toHsv
()
Defined by dojox/color/_base
Convert this Color to an HSV definition.
Returns: object
toRgb
()
Defined by dojo/_base/Color
Returns 3 component array of rgb values
Returns: Array
require(["dojo/_base/color"], function(Color){
var c = new Color("#000000");
console.log(c.toRgb()); // [0,0,0]
});
toRgba
()
Defined by dojo/_base/Color
Returns a 4 component array of rgba values from the color represented by this object.
Returns: Array
toString
()
Defined by dojo/_base/Color
Returns a visual representation of the color
Returns: undefined
© 2005–2017 JS Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/_base/Color.html