73bcce88
luigser
COMPONENTS
|
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../neon-shared-element-animation-behavior.html">
<link rel="import" href="../web-animations.html">
<!--
`<reverse-ripple-animation>` scales and transform an element such that it appears to ripple down from this element, to either
a shared element, or a screen position.
If using as a shared element animation in `<neon-animated-pages>`, use this animation in an `exit`
animation in the source page and in an `entry` animation in the destination page. Also, define the
reverse-ripple elements in the `sharedElements` property (not a configuration property, see
`Polymer.NeonSharedElementAnimatableBehavior`).
If using a screen position, define the `gesture` property.
Configuration:
```
{
name: 'reverse-ripple-animation`.
id: <shared-element-id>, /* set this or gesture */
gesture: {x: <page-x>, y: <page-y>}, /* set this or id */
timing: <animation-timing>,
toPage: <node>, /* define for the destination page */
fromPage: <node>, /* define for the source page */
}
```
-->
<script>
Polymer({
is: 'reverse-ripple-animation',
behaviors: [
Polymer.NeonSharedElementAnimationBehavior
],
configure: function(config) {
var shared = this.findSharedElements(config);
if (!shared) {
return null;
}
var translateX, translateY;
var fromRect = shared.from.getBoundingClientRect();
if (config.gesture) {
translateX = config.gesture.x - (fromRect.left + (fromRect.width / 2));
translateY = config.gesture.y - (fromRect.top + (fromRect.height / 2));
} else {
var toRect = shared.to.getBoundingClientRect();
translateX = (toRect.left + (toRect.width / 2)) - (fromRect.left + (fromRect.width / 2));
translateY = (toRect.top + (toRect.height / 2)) - (fromRect.top + (fromRect.height / 2));
}
var translate = 'translate(' + translateX + 'px,' + translateY + 'px)';
var size = Math.max(fromRect.width + Math.abs(translateX) * 2, fromRect.height + Math.abs(translateY) * 2);
var diameter = Math.sqrt(2 * size * size);
var scaleX = diameter / fromRect.width;
var scaleY = diameter / fromRect.height;
var scale = 'scale(' + scaleX + ',' + scaleY + ')';
this.setPrefixedProperty(shared.from, 'transformOrigin', '50% 50%');
shared.from.style.borderRadius = '50%';
this._effect = new KeyframeEffect(shared.from, [
{'transform': translate + ' ' + scale},
{'transform': translate + ' scale(0)'}
], this.timingFromConfig(config));
return this._effect;
},
complete: function() {
if (this.sharedElements) {
this.setPrefixedProperty(this.sharedElements.from, 'transformOrigin', '');
this.sharedElements.from.style.borderRadius = '';
}
}
});
</script>
|