The ColorRange
class is a simple utility that creates a range of colors to be used on elements of your choice. All you need is two colors and a selection of elements to apply a range of colors to and you're done.
ColorRange will work with MooTools 1.3 and 1.4 (without needing compatibility).
Default, a newly created ColorRange
object simply defines the range you supplied and nothing else. It can be used to apply the range to an element selection or selector. There are multiply ways to accomplish this; the following examples will all yield the same result:
#JS
// create a color range and use it on the page's menu items
var myRange = new ColorRange('#f00', [0, 0, 255]);
myRange.apply($$('#menu li'));
// apply a color range to the page's menu items
$$('#menu li').applyColorRange('#f00', '#00f');
// call a utility function to color the page's menu items
Color.applyRange('#f00', '#00f', '#menu li');
All the options of the ColorRange
class are described below.
#JS
var myRange = new ColorRange(from, to);
- from - (color) The starting color. This argument can be anything accepted by the constructor of
Color
. - to - (color) The ending color, like the first argument.
Applies a color range to a property of all the passed elements. Returns the ColorRange
instance.
#JS
myRange.apply(elements[, property]);
- elements - (elements or string) The selection of elements to apply the color range to, either an
Elements
object or a selector string. - property - (string, optional) The property to apply the colors to, defaults to
background-color
.
Utility to create a new color range from the Color
class.
#JS
Color.range(from, to);
See Constructor.
Utility to apply a color range to a selection of elements.
#JS
Color.applyRange(from, to, elements[, property]);
- from - (color) See Constructor.
- to - (color) See Constructor.
- elements - (elements or string) See apply.
- property - (string, optional) See apply.
Utility to apply a color range to an element collection.
#JS
$$('li.someClass').applyColorRange(from, to[, property]);
- from - (color) See Constructor.
- to - (color) See Constructor.
- property - (string, optional) See apply.
- update to MooTools 1.4 (functional code unchanged)
- initial release