|
6 | 6 | v-observe-visibility="handleVisibilityChange"
|
7 | 7 | >
|
8 | 8 | <div
|
| 9 | + ref="wrapper" |
9 | 10 | class="item-wrapper"
|
10 | 11 | :style="{ height: totalHeight + 'px' }"
|
11 | 12 | >
|
@@ -190,50 +191,54 @@ export default {
|
190 | 191 | let startIndex, endIndex
|
191 | 192 | let totalHeight
|
192 | 193 |
|
193 |
| - // Variable height mode |
194 |
| - if (itemHeight === null) { |
195 |
| - let h |
196 |
| - let a = 0 |
197 |
| - let b = count - 1 |
198 |
| - let i = ~~(count / 2) |
199 |
| - let oldI |
200 |
| -
|
201 |
| - // Searching for startIndex |
202 |
| - do { |
203 |
| - oldI = i |
204 |
| - h = heights[i].accumulator |
205 |
| - if (h < scroll.top) { |
206 |
| - a = i |
207 |
| - } else if (i < count - 1 && heights[i + 1].accumulator > scroll.top) { |
208 |
| - b = i |
| 194 | + if (!count) { |
| 195 | + startIndex = endIndex = totalHeight = 0 |
| 196 | + } else { |
| 197 | + // Variable height mode |
| 198 | + if (itemHeight === null) { |
| 199 | + let h |
| 200 | + let a = 0 |
| 201 | + let b = count - 1 |
| 202 | + let i = ~~(count / 2) |
| 203 | + let oldI |
| 204 | +
|
| 205 | + // Searching for startIndex |
| 206 | + do { |
| 207 | + oldI = i |
| 208 | + h = heights[i].accumulator |
| 209 | + if (h < scroll.top) { |
| 210 | + a = i |
| 211 | + } else if (i < count - 1 && heights[i + 1].accumulator > scroll.top) { |
| 212 | + b = i |
| 213 | + } |
| 214 | + i = ~~((a + b) / 2) |
| 215 | + } while (i !== oldI) |
| 216 | + i < 0 && (i = 0) |
| 217 | + startIndex = i |
| 218 | +
|
| 219 | + // For container style |
| 220 | + totalHeight = heights[count - 1].accumulator |
| 221 | +
|
| 222 | + // Searching for endIndex |
| 223 | + for (endIndex = i; endIndex < count && heights[endIndex].accumulator < scroll.bottom; endIndex++); |
| 224 | + if (endIndex === -1) { |
| 225 | + endIndex = items.length - 1 |
| 226 | + } else { |
| 227 | + endIndex++ |
| 228 | + // Bounds |
| 229 | + endIndex > count && (endIndex = count) |
209 | 230 | }
|
210 |
| - i = ~~((a + b) / 2) |
211 |
| - } while (i !== oldI) |
212 |
| - i < 0 && (i = 0) |
213 |
| - startIndex = i |
214 |
| -
|
215 |
| - // For container style |
216 |
| - totalHeight = heights[count - 1].accumulator |
217 |
| -
|
218 |
| - // Searching for endIndex |
219 |
| - for (endIndex = i; endIndex < count && heights[endIndex].accumulator < scroll.bottom; endIndex++); |
220 |
| - if (endIndex === -1) { |
221 |
| - endIndex = items.length - 1 |
222 | 231 | } else {
|
223 |
| - endIndex++ |
| 232 | + // Fixed height mode |
| 233 | + startIndex = ~~(scroll.top / itemHeight) |
| 234 | + endIndex = Math.ceil(scroll.bottom / itemHeight) |
| 235 | +
|
224 | 236 | // Bounds
|
| 237 | + startIndex < 0 && (startIndex = 0) |
225 | 238 | endIndex > count && (endIndex = count)
|
226 |
| - } |
227 |
| - } else { |
228 |
| - // Fixed height mode |
229 |
| - startIndex = ~~(scroll.top / itemHeight) |
230 |
| - endIndex = Math.ceil(scroll.bottom / itemHeight) |
231 | 239 |
|
232 |
| - // Bounds |
233 |
| - startIndex < 0 && (startIndex = 0) |
234 |
| - endIndex > count && (endIndex = count) |
235 |
| -
|
236 |
| - totalHeight = count * itemHeight |
| 240 | + totalHeight = count * itemHeight |
| 241 | + } |
237 | 242 | }
|
238 | 243 |
|
239 | 244 | this.totalHeight = totalHeight
|
|
0 commit comments