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
11 <link rel=
"import" href=
"../../polymer/polymer.html">
12 <link rel=
"import" href=
"../neon-shared-element-animation-behavior.html">
13 <link rel=
"import" href=
"../web-animations.html">
16 `<hero-animation>` is a shared element animation that scales and transform an element such that it
17 appears to be shared between two pages. Use this in `<neon-animated-pages>`. The source page
18 should use this animation in an 'exit' animation and set the `fromPage` configuration property to
19 itself, and the destination page should use this animation in an `entry` animation and set the
20 `toPage` configuration property to itself. They should also define the hero elements in the
21 `sharedElements` property (not a configuration property, see
22 `Polymer.NeonSharedElementAnimatableBehavior`).
27 name: 'hero-animation',
28 id: <shared-element-id>,
29 timing: <animation-timing>,
30 toPage: <node>, /* define for the destination page */
31 fromPage: <node>, /* define for the source page */
43 Polymer
.NeonSharedElementAnimationBehavior
46 configure: function(config
) {
47 var shared
= this.findSharedElements(config
);
52 var fromRect
= shared
.from.getBoundingClientRect();
53 var toRect
= shared
.to
.getBoundingClientRect();
55 var deltaLeft
= fromRect
.left
- toRect
.left
;
56 var deltaTop
= fromRect
.top
- toRect
.top
;
57 var deltaWidth
= fromRect
.width
/ toRect
.width
;
58 var deltaHeight
= fromRect
.height
/ toRect
.height
;
60 this.setPrefixedProperty(shared
.to
, 'transformOrigin', '0 0');
61 shared
.to
.style
.zIndex
= 10000;
62 shared
.from.style
.visibility
= 'hidden';
64 this._effect
= new KeyframeEffect(shared
.to
, [
65 {'transform': 'translate(' + deltaLeft
+ 'px,' + deltaTop
+ 'px) scale(' + deltaWidth
+ ',' + deltaHeight
+ ')'},
67 ], this.timingFromConfig(config
));
72 complete: function(config
) {
73 var shared
= this.findSharedElements(config
);
77 shared
.to
.style
.zIndex
= '';
78 shared
.from.style
.visibility
= '';