Skip to content

Commit 7f44fd2

Browse files
committed
Documented color animation.
1 parent d545209 commit 7f44fd2

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

pages/color-animation.md

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<script>{
2+
"title": "Color Animation",
3+
"excerpt": "Animate colors using .animate().",
4+
"termSlugs": {
5+
"category": [ "effects", "effects-core" ]
6+
}
7+
}</script>
8+
9+
jQuery UI effects core adds the ability to animate color properties using `rgb()`,
10+
`rgba()`, hex values, or even color names such as `"aqua"`. Simply include the
11+
jQuery UI effects core file and [`.animate()`](http://api.jquery.com/animate/)
12+
will gain support for colors.
13+
14+
The following properties are supported:
15+
16+
* `backgroundColor`
17+
* `borderBottomColor`
18+
* `borderLeftColor`
19+
* `borderRightColor`
20+
* `borderTopColor`
21+
* `color`
22+
* `columnRuleColor`
23+
* `outlineColor`
24+
* `textDecorationColor`
25+
* `textEmphasisColor`
26+
27+
Support for color animation comes from the
28+
[jQuery Color plugin](https://github.com/jquery/jquery-color). The Color plugin
29+
provides several functions for working with colors. For full documentation, please
30+
see the [jQuery Color documentation](https://github.com/jquery/jquery-color#readme).
31+
32+
## Class Animations
33+
34+
While there are use cases for directly animating individual color properties, it
35+
is often a better approach to contain the styles in a class. jQuery UI provides
36+
a few methods which will animate the addition or removal of a CSS class,
37+
specifically [`.addClass()`](/addClass/), [`.removeClass()`](/removeClass/),
38+
[`.toggleClass()`](/toggleClass/), and [`.switchClass()`](/switchClass/). These
39+
methods will automatically determine which properties need to change and apply
40+
the appropriate animations.
41+
42+
## Example
43+
44+
```html
45+
@partial(resources/color-animation.html)
46+
```
47+
48+
<iframe src="/resources/color-animation.html" width="100%" height="200"></iframe>

resources/color-animation.html

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Color Animation Demo</title>
6+
<link rel="stylehseet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
7+
<style>
8+
#elem {
9+
color: #006;
10+
background-color: #aaa;
11+
font-size: 25px;
12+
padding: 1em;
13+
text-align: center;
14+
}
15+
</style>
16+
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
17+
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
18+
</head>
19+
<body>
20+
21+
<div id="elem">color animations</div>
22+
<button id="toggle">animate colors</button>
23+
24+
<script>
25+
$( "#toggle" ).click(function() {
26+
$( "#elem" ).animate({
27+
color: "green",
28+
backgroundColor: "rgb( 20, 20, 20 )"
29+
});
30+
});
31+
</script>
32+
33+
</body>
34+
</html>

0 commit comments

Comments
 (0)