| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 @license | |
| 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.g
ithub.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/CONTRI
BUTORS.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/PATEN
TS.txt | |
| 9 --> | |
| 10 | |
| 11 | |
| 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"> | |
| 15 | |
| 16 <!-- | |
| 17 `<reverse-ripple-animation>` scales and transform an element such that it appear
s to ripple down from this element, to either | |
| 18 a shared element, or a screen position. | |
| 19 | |
| 20 If using as a shared element animation in `<neon-animated-pages>`, use this anim
ation 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 pr
operty, see | |
| 23 `Polymer.NeonSharedElementAnimatableBehavior`). | |
| 24 If using a screen position, define the `gesture` property. | |
| 25 Configuration: | |
| 26 ``` | |
| 27 { | |
| 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 */ | |
| 34 } | |
| 35 ``` | |
| 36 --> | |
| 37 | |
| 38 <script> | |
| 39 Polymer({ | |
| 40 is: 'reverse-ripple-animation', | |
| 41 | |
| 42 behaviors: [ | |
| 43 Polymer.NeonSharedElementAnimationBehavior | |
| 44 ], | |
| 45 | |
| 46 configure: function(config) { | |
| 47 var shared = this.findSharedElements(config); | |
| 48 if (!shared) { | |
| 49 return null; | |
| 50 } | |
| 51 | |
| 52 var translateX, translateY; | |
| 53 var fromRect = shared.from.getBoundingClientRect(); | |
| 54 if (config.gesture) { | |
| 55 translateX = config.gesture.x - (fromRect.left + (fromRect.width / 2)); | |
| 56 translateY = config.gesture.y - (fromRect.top + (fromRect.height / 2)); | |
| 57 } else { | |
| 58 var toRect = shared.to.getBoundingClientRect(); | |
| 59 translateX = (toRect.left + (toRect.width / 2)) - (fromRect.left + (from
Rect.width / 2)); | |
| 60 translateY = (toRect.top + (toRect.height / 2)) - (fromRect.top + (fromR
ect.height / 2)); | |
| 61 } | |
| 62 var translate = 'translate(' + translateX + 'px,' + translateY + 'px)'; | |
| 63 | |
| 64 var size = Math.max(fromRect.width + Math.abs(translateX) * 2, fromRect.he
ight + 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 + ')'; | |
| 69 | |
| 70 this.setPrefixedProperty(shared.from, 'transformOrigin', '50% 50%'); | |
| 71 shared.from.style.borderRadius = '50%'; | |
| 72 | |
| 73 this._effect = new KeyframeEffect(shared.from, [ | |
| 74 {'transform': translate + ' ' + scale}, | |
| 75 {'transform': translate + ' scale(0)'} | |
| 76 ], this.timingFromConfig(config)); | |
| 77 return this._effect; | |
| 78 }, | |
| 79 | |
| 80 complete: function() { | |
| 81 if (this.sharedElements) { | |
| 82 this.setPrefixedProperty(this.sharedElements.from, 'transformOrigin', ''
); | |
| 83 this.sharedElements.from.style.borderRadius = ''; | |
| 84 } | |
| 85 } | |
| 86 }); | |
| 87 </script> | |
| OLD | NEW |