3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
12 <link rel=
"import" href=
"../../polymer/polymer.html">
13 <link rel=
"import" href=
"../neon-shared-element-animation-behavior.html">
14 <link rel=
"import" href=
"../web-animations.html">
17 `<reverse-ripple-animation>` scales and transform an element such that it appears to ripple down from this element, to either
18 a shared element, or a screen position.
20 If using as a shared element animation in `<neon-animated-pages>`, use this animation in an `exit`
21 animation in the source page and in an `entry` animation in the destination page. Also, define the
22 reverse-ripple elements in the `sharedElements` property (not a configuration property, see
23 `Polymer.NeonSharedElementAnimatableBehavior`).
24 If using a screen position, define the `gesture` property.
28 name: 'reverse-ripple-animation`.
29 id: <shared-element-id>, /* set this or gesture */
30 gesture: {x: <page-x>, y: <page-y>}, /* set this or id */
31 timing: <animation-timing>,
32 toPage: <node>, /* define for the destination page */
33 fromPage: <node>, /* define for the source page */
40 is
: 'reverse-ripple-animation',
43 Polymer
.NeonSharedElementAnimationBehavior
46 configure: function(config
) {
47 var shared
= this.findSharedElements(config
);
52 var translateX
, translateY
;
53 var fromRect
= shared
.from.getBoundingClientRect();
55 translateX
= config
.gesture
.x
- (fromRect
.left
+ (fromRect
.width
/ 2));
56 translateY
= config
.gesture
.y
- (fromRect
.top
+ (fromRect
.height
/ 2));
58 var toRect
= shared
.to
.getBoundingClientRect();
59 translateX
= (toRect
.left
+ (toRect
.width
/ 2)) - (fromRect
.left
+ (fromRect
.width
/ 2));
60 translateY
= (toRect
.top
+ (toRect
.height
/ 2)) - (fromRect
.top
+ (fromRect
.height
/ 2));
62 var translate
= 'translate(' + translateX
+ 'px,' + translateY
+ 'px)';
64 var size
= Math
.max(fromRect
.width
+ Math
.abs(translateX
) * 2, fromRect
.height
+ Math
.abs(translateY
) * 2);
65 var diameter
= Math
.sqrt(2 * size
* size
);
66 var scaleX
= diameter
/ fromRect
.width
;
67 var scaleY
= diameter
/ fromRect
.height
;
68 var scale
= 'scale(' + scaleX
+ ',' + scaleY
+ ')';
70 this.setPrefixedProperty(shared
.from, 'transformOrigin', '50% 50%');
71 shared
.from.style
.borderRadius
= '50%';
73 this._effect
= new KeyframeEffect(shared
.from, [
74 {'transform': translate
+ ' ' + scale
},
75 {'transform': translate
+ ' scale(0)'}
76 ], this.timingFromConfig(config
));
80 complete: function() {
81 if (this.sharedElements
) {
82 this.setPrefixedProperty(this.sharedElements
.from, 'transformOrigin', '');
83 this.sharedElements
.from.style
.borderRadius
= '';