|
273 | 273 |
|
274 | 274 | /**
|
275 | 275 | * Fetches the latest properties from the DOM to ensure that
|
276 |
| - * this list is in sync with its contents. |
| 276 | + * this list is in sync with its contents. This is typically |
| 277 | + * only used once (per list) at initialization. |
277 | 278 | */
|
278 | 279 | TouchList.prototype.sync = function() {
|
279 | 280 | this.items = Array.prototype.slice.apply( this.element.children );
|
280 | 281 |
|
281 |
| - // Cache the list height so we don't need to go back to the DOM so much |
282 | 282 | this.listHeight = this.element.offsetHeight;
|
283 | 283 |
|
284 |
| - this.top.natural = this.element.scrollTop; |
285 |
| - this.top.value = this.top.natural; |
| 284 | + var item; |
286 | 285 |
|
287 | 286 | // One loop to get the properties we need from the DOM
|
288 | 287 | for( var i = 0, len = this.items.length; i < len; i++ ) {
|
289 |
| - var item = this.items[i]; |
| 288 | + item = this.items[i]; |
290 | 289 | item._offsetHeight = item.offsetHeight;
|
291 | 290 | item._offsetTop = item.offsetTop;
|
292 | 291 | item._offsetBottom = item._offsetTop + item._offsetHeight;
|
293 | 292 | item._state = '';
|
294 | 293 |
|
295 |
| - // Animating ppacity is a MAJOR performance hit on mobile so we can't allow it |
| 294 | + // Animating opacity is a MAJOR performance hit on mobile so we can't allow it |
296 | 295 | item.style.opacity = 1;
|
297 | 296 | }
|
298 | 297 |
|
| 298 | + this.top.natural = this.element.scrollTop; |
| 299 | + this.top.value = this.top.natural; |
| 300 | + this.top.max = item._offsetBottom - this.listHeight; |
| 301 | + |
299 | 302 | // Force an update
|
300 | 303 | this.update( true );
|
301 | 304 |
|
|
365 | 368 | if( this.touch.isAccellerating && sameDirection ) {
|
366 | 369 | clearInterval( this.touch.accellerateTimeout );
|
367 | 370 |
|
368 |
| - // Increase velocity exponentially |
| 371 | + // Increase velocity significantly |
369 | 372 | this.velocity += ( this.touch.previous - this.touch.value ) / 10;
|
370 | 373 | }
|
371 | 374 | else {
|
|
383 | 386 | var distanceMoved = this.touch.start - this.touch.value;
|
384 | 387 |
|
385 | 388 | if( !this.touch.isAccellerating ) {
|
| 389 | + // Apply velocity based on the start position of the touch |
386 | 390 | this.velocity = ( this.touch.start - this.touch.value ) / 10;
|
387 | 391 | }
|
388 | 392 |
|
|
419 | 423 | if( this.velocity || this.touch.offset ) {
|
420 | 424 | // Scroll the DOM and add on the offset from touch
|
421 | 425 | this.element.scrollTop = scrollTop;
|
422 |
| - scrollTop = this.element.scrollTop; |
| 426 | + |
| 427 | + // Keep the scroll value within bounds |
| 428 | + scrollTop = Math.max( 0, Math.min( this.element.scrollTop, this.top.max ) ); |
423 | 429 |
|
424 | 430 | // Cache the currently set scroll top and touch offset
|
425 | 431 | this.top.value = scrollTop - this.touch.offset;
|
|
0 commit comments