| 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 <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"> |  | 
|  14  |  | 
|  15 <!-- |  | 
|  16 `<hero-animation>` is a shared element animation that scales and transform an el
    ement 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` configur
    ation property to |  | 
|  19 itself, and the destination page should use this animation in an `entry` animati
    on and set the |  | 
|  20 `toPage` configuration property to itself. They should also define the hero elem
    ents in the |  | 
|  21 `sharedElements` property (not a configuration property, see |  | 
|  22 `Polymer.NeonSharedElementAnimatableBehavior`). |  | 
|  23  |  | 
|  24 Configuration: |  | 
|  25 ``` |  | 
|  26 { |  | 
|  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 */ |  | 
|  32 } |  | 
|  33 ``` |  | 
|  34 --> |  | 
|  35  |  | 
|  36 <script> |  | 
|  37  |  | 
|  38   Polymer({ |  | 
|  39  |  | 
|  40     is: 'hero-animation', |  | 
|  41  |  | 
|  42     behaviors: [ |  | 
|  43       Polymer.NeonSharedElementAnimationBehavior |  | 
|  44     ], |  | 
|  45  |  | 
|  46     configure: function(config) { |  | 
|  47       var shared = this.findSharedElements(config); |  | 
|  48       if (!shared) { |  | 
|  49         return; |  | 
|  50       } |  | 
|  51  |  | 
|  52       var fromRect = shared.from.getBoundingClientRect(); |  | 
|  53       var toRect = shared.to.getBoundingClientRect(); |  | 
|  54  |  | 
|  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; |  | 
|  59  |  | 
|  60       this.setPrefixedProperty(shared.to, 'transformOrigin', '0 0'); |  | 
|  61       shared.to.style.zIndex = 10000; |  | 
|  62       shared.from.style.visibility = 'hidden'; |  | 
|  63  |  | 
|  64       this._effect = new KeyframeEffect(shared.to, [ |  | 
|  65         {'transform': 'translate(' + deltaLeft + 'px,' + deltaTop + 'px) scale('
     + deltaWidth + ',' + deltaHeight + ')'}, |  | 
|  66         {'transform': 'none'} |  | 
|  67       ], this.timingFromConfig(config)); |  | 
|  68  |  | 
|  69       return this._effect; |  | 
|  70     }, |  | 
|  71  |  | 
|  72     complete: function(config) { |  | 
|  73       var shared = this.findSharedElements(config); |  | 
|  74       if (!shared) { |  | 
|  75         return null; |  | 
|  76       } |  | 
|  77       shared.to.style.zIndex = ''; |  | 
|  78       shared.from.style.visibility = ''; |  | 
|  79     } |  | 
|  80  |  | 
|  81   }); |  | 
|  82  |  | 
|  83 </script> |  | 
| OLD | NEW |