-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic-spread-fit.html
More file actions
95 lines (75 loc) · 1.99 KB
/
basic-spread-fit.html
File metadata and controls
95 lines (75 loc) · 1.99 KB
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
<!--
Spreads out a set of items horizontally so they take equal space.
This is a variant of basic-spread-items which automatically sizes itself to
contain the tallest/widest items in a list.
@element basic-spread-fit
-->
<link rel="import" href="../basic-aspect/basic-aspect.html">
<link rel="import" href="../basic-stack/basic-stack.html">
<dom-module id="basic-spread-fit">
<template>
<style>
:host {
display: inline-block;
overflow: hidden;
position: relative;
}
basic-stack {
display: inline-block;
}
#stack ::content .item {
-webkit-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
}
</style>
<basic-stack id="stack">
<content></content>
</basic-stack>
</template>
</dom-module>
<script>
Polymer({
behaviors: [Basic.Aspect],
contribute: {
itemAdded: function(item) {
/*
* We want to be able to style children that might be reprojected. This
* is easy to accomplish in native Shadow DOM, but hard in Shady DOM.
* To simplify this, we apply a class to all children, then define a rule
* to style everything with that class.
*/
item.classList.add('item');
}
},
is: 'basic-spread-fit',
properties: {
target: {
value: 'shadow'
}
},
ready: function() {
this.$.stack.addEventListener('basic-layout', function(event) {
this._layout(event.detail.width, event.detail.height);
}.bind(this));
},
/**
* Force the component to recalculate its size.
*
* @method recalc
*/
recalc: function() {
this.$.stack.recalc();
},
_layout: function(width, height) {
var items = this.collective.items;
var count = items.length;
this.style.width = (count * width) + 'px';
this.style.height = height + 'px';
items.forEach(function(element, index) {
var offset = (index + 0.5) * width;
element.style.left = offset + 'px';
element.style.top = '50%';
});
}
});
</script>