Color Animation


jQuery UI特效内核使用rgb()rgba(),16进制值,甚至颜色名称比如"aqua"给颜色增加了动画新特性。只需要包含 jQuery UI特效内核文件和.animate()就可以获得对各种颜色的支持。

支持以下属性:

  • backgroundColor
  • borderBottomColor
  • borderLeftColor
  • borderRightColor
  • borderTopColor
  • color
  • columnRuleColor
  • outlineColor
  • textDecorationColor
  • textEmphasisColor

对颜色动画的技术支持来自 jQuery Color plugin。颜色插件提供了多个函数来处理各种颜色。 查看完整文档,请访问jQuery Color documentation

Class Animations(与动画关联的CSS类)

当为单独的颜色属性直接呈现动画效果时,将样式包含在css类中是一个很好的处理方式。 jQuery UI提供了一系列方法,这些方法可以根据新增的CSS类来呈现动画,还可以删除任何CSS类。 这些方法包含.addClass(), .removeClass(), .toggleClass().switchClass()。 这些方法将自动决定哪些属性需要被改变并且对其应用适当的动画。

Example

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

Demo: