This repository has been archived by the owner on Mar 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
paper-dropdown-transition.html
180 lines (154 loc) · 5.49 KB
/
paper-dropdown-transition.html
1
2
3
4
5
6
7
8
9
10
11
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<!--
`paper-dropdown-transition` is a transition for `paper-dropdown`.
Add the class `menu` to a `core-selector` child of the `paper-dropdown` to
enable the optional list cascade transition.
@group Paper Elements
@class paper-dropdown-transition
@extends core-transition-css
@status unstable
-->
<link href="../polymer/polymer.html" rel="import">
<link href="../core-transition/core-transition-css.html" rel="import">
<link href="../core-animation/web-animations.html" rel="import">
<polymer-element name="paper-dropdown-transition" extends="core-transition-css">
<template>
<link href="paper-dropdown-transition.css" rel="stylesheet" no-shim>
</template>
<script>
Polymer('paper-dropdown-transition', {
publish: {
/**
* The duration of the transition in ms. You can also set the duration by
* setting a `duration` attribute on the target:
*
* <paper-dropdown duration="1000"></paper-dropdown>
*
* @attribute duration
* @type number
* @default 500
*/
duration: 500
},
setup: function(node) {
this.super(arguments);
var to = {
'top': '0%',
'left': '0%',
'bottom': '100%',
'right': '100%'
};
var bg = node.$.background;
bg.style.webkitTransformOrigin = to[node.halign] + ' ' + to[node.valign];
bg.style.transformOrigin = to[node.halign] + ' ' + to[node.valign];
},
transitionOpened: function(node, opened) {
this.super(arguments);
if (opened) {
if (this.player) {
this.player.cancel();
}
var duration = Number(node.getAttribute('duration')) || this.duration;
var anims = [];
var size = node.getBoundingClientRect();
var ink = node.$.ripple;
// var offset = 40 / Math.max(size.width, size.height);
var offset = 0.2;
anims.push(new Animation(ink, [{
'opacity': 0.9,
'transform': 'scale(0)',
}, {
'opacity': 0.9,
'transform': 'scale(1)'
}], {
duration: duration * offset,
}));
// XXX: cancel() seems not to be working until chrome 41 so set the opacity for the
// background here to prevent a flash.
anims.push(new Animation(node.$.background, [{
'opacity': 0,
'transform': 'scale(0)'
}, {
'opacity': 0,
'transform': 'scale(0)'
}], {
duration: 0,
delay: 0,
fill: 'forwards'
}));
var bg = node.$.background;
var sx = 40 / size.width;
var sy = 40 / size.height;
anims.push(new Animation(bg, [{
'opacity': 0.9,
'transform': 'scale(' + sx + ',' + sy + ')',
}, {
'opacity': 1,
'transform': 'scale(' + Math.max(sx, 0.95) + ',' + Math.max(sy, 0.5) + ')'
}, {
'opacity': 1,
'transform': 'scale(1, 1)'
}], {
delay: duration * offset,
duration: duration * (1 - offset),
fill: 'forwards'
}));
var menu = node.querySelector('.menu');
if (menu) {
var items = menu.items || menu.children.array();
var itemDelay = offset + (1 - offset) / 2;
var itemDuration = duration * (1 - itemDelay) / items.length;
var reverse = this.valign === 'bottom';
items.forEach(function(item, i) {
anims.push(new Animation(item, [{
'opacity': 0
}, {
'opacity': 1
}], {
delay: duration * itemDelay + itemDuration * (reverse ? items.length - 1 - i : i),
duration: itemDuration,
fill: 'both'
}));
}.bind(this));
anims.push(new Animation(node.$.scroller, [{
'opacity': 1
}, {
'opacity': 1
}], {
delay: duration * itemDelay,
duration: itemDuration * items.length,
fill: 'both'
}));
} else {
anims.push(new Animation(node.$.scroller, [{
'opacity': 0
}, {
'opacity': 1
}], {
delay: duration * (offset + (1 - offset) / 2),
duration: duration * 0.5,
fill: 'both'
}));
}
var group = new AnimationGroup(anims, {
easing: 'cubic-bezier(0.4, 0, 0.2, 1)'
});
this.player = document.timeline.play(group);
this.player.onfinish = function() {
this.fire('core-transitionend', this, node);
}.bind(this);
} else {
this.fire('core-transitionend', this, node);
}
},
});
</script>
</polymer-element>
<paper-dropdown-transition id="paper-dropdown-transition"></paper-dropdown-transition>