2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10 <link rel=
"import" href=
"../polymer/polymer.html">
11 <link rel=
"import" href=
"core-animation.html">
14 @group Polymer Core Elements
16 `core-animation-group` combines `core-animation` or `core-animation-group` elements to
17 create a grouped web animation. The group may be parallel (type is `par`) or sequential
18 (type is `seq`). Parallel groups play all the children elements simultaneously, and
19 sequential groups play the children one after another.
21 Example of an animation group to rotate and then fade an element:
23 <core-animation-group type="seq">
24 <core-animation id="fadeout" duration="500">
25 <core-animation-keyframe>
26 <core-animation-prop name="transform" value="rotate(0deg)"></core-animation-prop>
27 <core-animation-prop name="transform" value="rotate(45deg)"></core-animation-prop>
28 </core-animation-keyframe>
30 <core-animation id="fadeout" duration="500">
31 <core-animation-keyframe>
32 <core-animation-prop name="opacity" value="1"></core-animation-prop>
33 </core-animation-keyframe>
34 <core-animation-keyframe>
35 <core-animation-prop name="opacity" value="0"></core-animation-prop>
36 </core-animation-keyframe>
38 </core-animation-group>
40 @element core-animation-group
44 <polymer-element name=
"core-animation-group" constructor=
"CoreAnimationGroup" extends=
"core-animation" attributes=
"type">
48 var ANIMATION_GROUPS
= {
49 'par': AnimationGroup
,
50 'seq': AnimationSequence
57 * If target is set, any children without a target will be assigned the group's
58 * target when this property is set.
61 * @type HTMLElement|Node|Array|Array<HTMLElement|Node>
65 * For a `core-animation-group`, a duration of "auto" means the duration should
66 * be the specified duration of its children. If set to anything other than
67 * "auto", any children without a set duration will be assigned the group's duration.
73 duration
: {value
: 'auto', reflect
: true},
76 * The type of the animation group. 'par' creates a parallel group and 'seq' creates
83 type
: {value
: 'par', reflect
: true}
86 typeChanged: function() {
90 targetChanged: function() {
91 // Only propagate target to children animations if it's defined.
93 this.doOnChildren(function(c
) {
94 c
.target
= this.target
;
99 durationChanged: function() {
100 if (this.duration
&& this.duration
!== 'auto') {
101 this.doOnChildren(function(c
) {
102 // Propagate to children that is not a group and has no
103 // duration specified.
104 if (!c
.type
&& (!c
.duration
|| c
.duration
=== 'auto')) {
105 c
.duration
= this.duration
;
111 doOnChildren: function(inFn
) {
112 var children
= this.children
;
113 if (!children
.length
) {
114 children
= this.shadowRoot
? this.shadowRoot
.childNodes
: [];
116 Array
.prototype.forEach
.call(children
, function(c
) {
117 // TODO <template> in the way
122 makeAnimation: function() {
123 return new ANIMATION_GROUPS
[this.type
](this.childAnimations
, this.timingProps
);
126 hasTarget: function() {
127 var ht
= this.target
!== null;
129 this.doOnChildren(function(c
) {
130 ht
= ht
|| c
.hasTarget();
137 // Propagate target and duration to child animations first.
138 this.durationChanged();
139 this.targetChanged();
140 this.doOnChildren(function(c
) {
146 get childAnimationElements() {
148 this.doOnChildren(function(c
) {
149 if (c
.makeAnimation
) {
156 get childAnimations() {
158 this.doOnChildren(function(c
) {
160 list
.push(c
.animation
);