|
58 | 58 | start: start, // start index.
|
59 | 59 | end: start + keeps, // end index.
|
60 | 60 | keeps: keeps, // nums keeping in real dom.
|
61 |
| - total: 0, // all items count, update in render filter. |
62 |
| - offset: 0, // cache current scroll offset. |
63 |
| - offsetAll: 0, // cache all the scroll offset. |
64 |
| - direct: 'd', // cache scroll direction. |
| 61 | + total: 0, // all items count, update in filter. |
| 62 | + offsetAll: 0, // cache all the scrollable offset. |
65 | 63 | paddingTop: 0, // container wrapper real padding-top.
|
66 | 64 | paddingBottom: 0, // container wrapper real padding-bottom.
|
67 |
| - varCache: {}, // cache variable index height and padding offset. |
| 65 | + varCache: {}, // object to cache variable index height and scroll offset. |
68 | 66 | varAverSize: 0, // average/estimate item height before variable be calculated.
|
69 | 67 | varLastCalcIndex: 0 // last calculated variable height/offset index, always increase.
|
70 | 68 | }
|
71 | 69 | },
|
72 | 70 |
|
73 | 71 | watch: {
|
74 |
| - remain: function () { |
75 |
| - this.alter = 'remain' |
76 |
| - }, |
77 | 72 | size: function () {
|
78 | 73 | this.alter = 'size'
|
79 | 74 | },
|
| 75 | + remain: function () { |
| 76 | + this.alter = 'remain' |
| 77 | + }, |
80 | 78 | bench: function () {
|
81 | 79 | this.alter = 'bench'
|
82 | 80 | },
|
|
90 | 88 | var delta = this.delta
|
91 | 89 | var offset = this.$refs.vsl.scrollTop
|
92 | 90 |
|
93 |
| - delta.direct = delta.offset > offset ? 'u' : 'd' |
94 |
| - delta.offset = offset |
95 |
| - |
96 | 91 | if (!offset && delta.total) {
|
97 | 92 | this.triggerEvent('totop')
|
98 | 93 | }
|
|
106 | 101 | }
|
107 | 102 |
|
108 | 103 | if (this.onscroll) {
|
109 |
| - this.onscroll(e, { |
110 |
| - end: delta.end, |
111 |
| - start: delta.start, |
112 |
| - offset: offset |
113 |
| - }) |
| 104 | + this.onscroll(e, offset) |
114 | 105 | }
|
115 | 106 | },
|
116 | 107 |
|
117 |
| - // update render zone by moving offset. |
| 108 | + // update render zone by scroll offset. |
118 | 109 | updateZone: function (offset) {
|
119 | 110 | var overs
|
120 | 111 | if (this.variable) {
|
|
137 | 128 | this.$forceUpdate()
|
138 | 129 | },
|
139 | 130 |
|
140 |
| - // return the scroll passed items count in variable height. |
| 131 | + // return the scroll passed items count in variable. |
141 | 132 | getVarOvers: function (offset) {
|
142 | 133 | var low = 0
|
143 | 134 | var middle = 0
|
|
149 | 140 | middle = low + Math.floor((high - low) / 2)
|
150 | 141 | middleOffset = this.getVarOffset(middle)
|
151 | 142 |
|
152 |
| - // calculate the average variable size at first binary search. |
| 143 | + // calculate the average variable height at first binary search. |
153 | 144 | if (!delta.varAverSize) {
|
154 | 145 | delta.varAverSize = Math.floor(middleOffset / middle)
|
155 | 146 | }
|
|
166 | 157 | return low > 0 ? --low : 0
|
167 | 158 | },
|
168 | 159 |
|
169 |
| - // get the variable height index scroll offset. |
| 160 | + // return a variable scroll offset from given index. |
170 | 161 | getVarOffset: function (index, nocache) {
|
171 | 162 | var delta = this.delta
|
172 | 163 | var cache = delta.varCache[index]
|
|
191 | 182 | return offset
|
192 | 183 | },
|
193 | 184 |
|
194 |
| - // return a variable size (height) from a given index. |
| 185 | + // return a variable size (height) from given index. |
195 | 186 | getVarSize: function (index, nocache) {
|
196 | 187 | var cache = this.delta.varCache[index]
|
197 | 188 | return (!nocache && cache && cache.size) || this.variable(index) || 0
|
|
217 | 208 | }
|
218 | 209 | },
|
219 | 210 |
|
220 |
| - // retun the variable all heights use to judge reach to bottom. |
| 211 | + // retun the variable all heights use to judge reach bottom. |
221 | 212 | getVarAllHeight: function () {
|
222 | 213 | var delta = this.delta
|
223 | 214 | if (delta.total - delta.end <= delta.keeps || delta.varLastCalcIndex === delta.total - 1) {
|
|
227 | 218 | }
|
228 | 219 | },
|
229 | 220 |
|
230 |
| - // the ONLY ONE public method, let the parent to update variable by index. |
| 221 | + // the ONLY ONE public method, allow the parent update variable by index. |
231 | 222 | updateVariable: function (index) {
|
232 |
| - // update all the offfsets ahead of index. |
| 223 | + // clear/update all the offfsets and heights ahead of index. |
233 | 224 | this.getVarOffset(index, true)
|
234 | 225 | },
|
235 | 226 |
|
|
265 | 256 | }
|
266 | 257 | },
|
267 | 258 |
|
268 |
| - // set manual scrollTop. |
| 259 | + // set manual scroll top. |
269 | 260 | setScrollTop: function (scrollTop) {
|
270 | 261 | this.$refs.vsl.scrollTop = scrollTop
|
271 | 262 | },
|
|
318 | 309 | delta.keeps = this.remain + (this.bench || this.remain)
|
319 | 310 |
|
320 | 311 | var alterStart = this.alter === 'start'
|
321 |
| - var oldStart = alterStart ? this.start : delta.start |
322 |
| - var zone = this.getZone(oldStart) |
| 312 | + var calcStart = alterStart ? this.start : delta.start |
| 313 | + var zone = this.getZone(calcStart) |
323 | 314 |
|
324 |
| - // if start change, update scroll position. |
325 |
| - if (alterStart) { |
| 315 | + // if start or size change, update scroll position. |
| 316 | + if (alterStart || this.alter === 'size') { |
326 | 317 | this.$nextTick(this.setScrollTop.bind(this, this.variable
|
327 | 318 | ? this.getVarOffset(zone.isLast ? delta.total : zone.start)
|
328 | 319 | : zone.isLast ? delta.total * this.size : zone.start * this.size)
|
329 | 320 | )
|
330 | 321 | }
|
331 | 322 |
|
332 | 323 | // if points out difference, force update once again.
|
333 |
| - if (oldStart !== zone.start || this.alter) { |
| 324 | + if (calcStart !== zone.start || this.alter) { |
334 | 325 | this.alter = ''
|
335 | 326 | delta.end = zone.end
|
336 | 327 | delta.start = zone.start
|
|
0 commit comments