|
110 | 110 | this.triggerEvent('totop')
|
111 | 111 | }
|
112 | 112 |
|
113 |
| - this.updateZone(offset) |
| 113 | + if (delta.total > delta.keeps) { |
| 114 | + this.updateZone(offset) |
| 115 | + } |
114 | 116 |
|
115 | 117 | if (this.onscroll) {
|
116 | 118 | this.onscroll(e, {
|
|
173 | 175 | },
|
174 | 176 |
|
175 | 177 | // get the variable height index scroll offset.
|
176 |
| - getVarOffset: function (index) { |
| 178 | + getVarOffset: function (index, nocache) { |
177 | 179 | var delta = this.delta
|
178 | 180 | var cache = delta.varCache[index]
|
179 | 181 |
|
180 |
| - if (cache) { |
| 182 | + if (cache && !nocache) { |
181 | 183 | return cache.offset
|
182 | 184 | }
|
183 | 185 |
|
184 | 186 | var offset = 0
|
185 | 187 | for (var i = 0; i < index; i++) {
|
186 |
| - var size = this.getVarSize(i) |
| 188 | + var size = this.getVarSize(i, nocache) |
187 | 189 | delta.varCache[i] = {
|
188 | 190 | size: size,
|
189 | 191 | offset: offset
|
190 | 192 | }
|
191 | 193 | offset += size
|
192 | 194 | }
|
193 | 195 |
|
194 |
| - delta.varLastCalcIndex = Math.max(delta.varLastCalcIndex, index) |
| 196 | + delta.varLastCalcIndex = Math.max(delta.varLastCalcIndex, index - 1) |
195 | 197 | delta.varLastCalcIndex = Math.min(delta.varLastCalcIndex, delta.total - 1)
|
196 | 198 |
|
197 | 199 | return offset
|
198 | 200 | },
|
199 | 201 |
|
200 | 202 | // return a variable size (height) from a given index.
|
201 |
| - getVarSize: function (index) { |
| 203 | + getVarSize: function (index, nocache) { |
202 | 204 | var cache = this.delta.varCache[index]
|
203 |
| - return (cache && cache.size) || this.variable(index) || 0 |
| 205 | + return (!nocache && cache && cache.size) || this.variable(index) || 0 |
204 | 206 | },
|
205 | 207 |
|
206 | 208 | // return the variable paddingTop base current zone.
|
|
223 | 225 | }
|
224 | 226 | },
|
225 | 227 |
|
| 228 | + // the ONLY ONE public method, let the parent to update variable by index. |
| 229 | + updateVariable: function (index) { |
| 230 | + // update all the offfsets ahead of index. |
| 231 | + this.getVarOffset(index, true) |
| 232 | + }, |
| 233 | + |
226 | 234 | // avoid overflow range.
|
227 | 235 | isOverflow: function (start) {
|
228 | 236 | var delta = this.delta
|
229 |
| - var overflow = (delta.total - delta.keeps > 0) && (start + this.remain >= delta.total) |
| 237 | + var overflow = (delta.total > delta.keeps) && (start + this.remain >= delta.total) |
230 | 238 | if (overflow && delta.direct === 'd') {
|
231 | 239 | this.triggerEvent('tobottom')
|
232 | 240 | }
|
|
248 | 256 | var start, end
|
249 | 257 | var delta = this.delta
|
250 | 258 |
|
251 |
| - index = parseInt(index, 10) || 0 |
252 |
| - index = index >= delta.total ? (delta.total - 1) : (index < 0 ? 0 : index) |
| 259 | + index = parseInt(index, 10) |
| 260 | + index = index < 0 ? 0 : index |
253 | 261 |
|
254 | 262 | var overflow = this.isOverflow(index)
|
255 | 263 | // if overflow range return the last zone.
|
|
0 commit comments