| OLD | NEW |
| (Empty) |
| 1 | |
| 2 Polymer('paper-dropdown-transition', { | |
| 3 | |
| 4 publish: { | |
| 5 | |
| 6 /** | |
| 7 * The duration of the transition in ms. You can also set the duration b
y | |
| 8 * setting a `duration` attribute on the target: | |
| 9 * | |
| 10 * <paper-dropdown duration="1000"></paper-dropdown> | |
| 11 * | |
| 12 * @attribute duration | |
| 13 * @type number | |
| 14 * @default 500 | |
| 15 */ | |
| 16 duration: 500 | |
| 17 | |
| 18 }, | |
| 19 | |
| 20 setup: function(node) { | |
| 21 this.super(arguments); | |
| 22 | |
| 23 var to = { | |
| 24 'top': '0%', | |
| 25 'left': '0%', | |
| 26 'bottom': '100%', | |
| 27 'right': '100%' | |
| 28 }; | |
| 29 | |
| 30 var bg = node.$.background; | |
| 31 bg.style.webkitTransformOrigin = to[node.halign] + ' ' + to[node.valign]
; | |
| 32 bg.style.transformOrigin = to[node.halign] + ' ' + to[node.valign]; | |
| 33 }, | |
| 34 | |
| 35 transitionOpened: function(node, opened) { | |
| 36 this.super(arguments); | |
| 37 | |
| 38 if (opened) { | |
| 39 if (this.player) { | |
| 40 this.player.cancel(); | |
| 41 } | |
| 42 | |
| 43 var duration = Number(node.getAttribute('duration')) || this.duration; | |
| 44 | |
| 45 var anims = []; | |
| 46 | |
| 47 var size = node.getBoundingClientRect(); | |
| 48 | |
| 49 var ink = node.$.ripple; | |
| 50 // var offset = 40 / Math.max(size.width, size.height); | |
| 51 var offset = 0.2; | |
| 52 anims.push(new Animation(ink, [{ | |
| 53 'opacity': 0.9, | |
| 54 'transform': 'scale(0)', | |
| 55 }, { | |
| 56 'opacity': 0.9, | |
| 57 'transform': 'scale(1)' | |
| 58 }], { | |
| 59 duration: duration * offset | |
| 60 })); | |
| 61 | |
| 62 var bg = node.$.background; | |
| 63 var sx = 40 / size.width; | |
| 64 var sy = 40 / size.height; | |
| 65 anims.push(new Animation(bg, [{ | |
| 66 'opacity': 0.9, | |
| 67 'transform': 'scale(' + sx + ',' + sy + ')', | |
| 68 }, { | |
| 69 'opacity': 1, | |
| 70 'transform': 'scale(' + Math.max(sx, 0.95) + ',' + Math.max(sy, 0.5)
+ ')' | |
| 71 }, { | |
| 72 'opacity': 1, | |
| 73 'transform': 'scale(1, 1)' | |
| 74 }], { | |
| 75 delay: duration * offset, | |
| 76 duration: duration * (1 - offset), | |
| 77 fill: 'forwards' | |
| 78 })); | |
| 79 | |
| 80 var menu = node.querySelector('.menu'); | |
| 81 if (menu) { | |
| 82 var items = menu.items || menu.children.array(); | |
| 83 var itemDelay = offset + (1 - offset) / 2; | |
| 84 var itemDuration = duration * (1 - itemDelay) / items.length; | |
| 85 var reverse = this.valign === 'bottom'; | |
| 86 | |
| 87 items.forEach(function(item, i) { | |
| 88 anims.push(new Animation(item, [{ | |
| 89 'opacity': 0 | |
| 90 }, { | |
| 91 'opacity': 1 | |
| 92 }], { | |
| 93 delay: duration * itemDelay + itemDuration * (reverse ? items.le
ngth - 1 - i : i), | |
| 94 duration: itemDuration, | |
| 95 fill: 'both' | |
| 96 })); | |
| 97 }.bind(this)); | |
| 98 | |
| 99 anims.push(new Animation(node.$.scroller, [{ | |
| 100 'opacity': 1 | |
| 101 }, { | |
| 102 'opacity': 1 | |
| 103 }], { | |
| 104 delay: duration * itemDelay, | |
| 105 duration: itemDuration * items.length, | |
| 106 fill: 'both' | |
| 107 })); | |
| 108 | |
| 109 } else { | |
| 110 anims.push(new Animation(node.$.scroller, [{ | |
| 111 'opacity': 0 | |
| 112 }, { | |
| 113 'opacity': 1 | |
| 114 }], { | |
| 115 delay: duration * (offset + (1 - offset) / 2), | |
| 116 duration: duration * 0.5, | |
| 117 fill: 'both' | |
| 118 })); | |
| 119 } | |
| 120 | |
| 121 var group = new AnimationGroup(anims, { | |
| 122 easing: 'cubic-bezier(0.4, 0, 0.2, 1)' | |
| 123 }); | |
| 124 this.player = document.timeline.play(group); | |
| 125 this.player.onfinish = function() { | |
| 126 this.fire('core-transitionend', this, node); | |
| 127 }.bind(this); | |
| 128 | |
| 129 } else { | |
| 130 this.fire('core-transitionend', this, node); | |
| 131 } | |
| 132 }, | |
| 133 | |
| 134 }); | |
| 135 | |
| OLD | NEW |