|
1 |
| -<div ref:viewport on:scroll='refresh()' style='height: {height};' bind:offsetHeight="viewportHeight"> |
| 1 | +<div ref:viewport on:scroll='refresh()' style='height: {height};' bind:offsetHeight="_viewportHeight"> |
2 | 2 | <div ref:container style='padding-top: {_top}px; padding-bottom: {_bottom}px;'>
|
3 | 3 | {#each visible as item (item.index)}
|
4 | 4 | <div class='row'>
|
|
23 | 23 | <script>
|
24 | 24 | export default {
|
25 | 25 | data() {
|
26 |
| - return { start: 0, end: 0, height: '100%', itemHeight: 0, _top: 0, _bottom: 0, _props: {} }; |
| 26 | + return { |
| 27 | + start: 0, |
| 28 | + end: 0, |
| 29 | + height: '100%', |
| 30 | + itemHeight: 0, |
| 31 | + _viewportHeight: 0, |
| 32 | + _top: 0, |
| 33 | + _bottom: 0, |
| 34 | + _props: {} |
| 35 | + }; |
27 | 36 | },
|
28 | 37 |
|
29 | 38 | computed: {
|
|
55 | 64 | }
|
56 | 65 |
|
57 | 66 | this.on('state', ({ changed, previous, current }) => {
|
58 |
| - if (changed.items || changed.height || changed.itemHeight || changed.viewportHeight) { |
| 67 | + if (changed.items || changed.height || changed.itemHeight || changed._viewportHeight) { |
59 | 68 | if (current.itemHeight && (changed.itemHeight || current.items.length > this.heightMap.length)) {
|
60 | 69 | this.heightMap = current.items.map(() => current.itemHeight);
|
61 | 70 | }
|
|
87 | 96 |
|
88 | 97 | methods: {
|
89 | 98 | initialise() {
|
90 |
| - const { items, itemHeight, viewportHeight } = this.get(); |
| 99 | + const { items, itemHeight, _viewportHeight } = this.get(); |
91 | 100 |
|
92 | 101 | if (itemHeight) {
|
93 | 102 | this.heightMap = items.map(item => itemHeight);
|
94 | 103 | this.set({
|
95 |
| - end: Math.min(items.length, Math.ceil(viewportHeight / itemHeight)), |
| 104 | + end: Math.min(items.length, Math.ceil(_viewportHeight / itemHeight)), |
96 | 105 | _bottom: items.length * itemHeight
|
97 | 106 | });
|
98 | 107 | } else {
|
99 | 108 | let height = 0;
|
100 | 109 | let i = 0;
|
101 | 110 |
|
102 |
| - while (height < viewportHeight && i < items.length) { |
| 111 | + while (height < _viewportHeight && i < items.length) { |
103 | 112 | this.set({ end: i + 1 });
|
104 | 113 |
|
105 | 114 | const rowHeight = this.heightMap[i] = this.rows[i].offsetHeight;
|
|
120 | 129 | },
|
121 | 130 |
|
122 | 131 | refresh() {
|
123 |
| - const { items, start, end, itemHeight, viewportHeight } = this.get(); |
| 132 | + const { items, start, end, itemHeight, _viewportHeight } = this.get(); |
124 | 133 | const { scrollTop } = this.refs.viewport;
|
125 | 134 |
|
126 | 135 | let paddingTop = 0;
|
|
145 | 154 | const newStart = i++;
|
146 | 155 |
|
147 | 156 | for (; i < items.length; i += 1) {
|
148 |
| - if (offset >= scrollTop + viewportHeight) break; |
| 157 | + if (offset >= scrollTop + _viewportHeight) break; |
149 | 158 | offset += this.heightMap[i];
|
150 | 159 | }
|
151 | 160 |
|
|
0 commit comments