| 38 | // rAF loop helper |
| 39 | |
| 40 | function loop (timeCurrent) { |
| 41 | // store time scroll started, if not started already |
| 42 | if (!timeStart) { |
| 43 | timeStart = timeCurrent |
| 44 | } |
| 45 | |
| 46 | // determine time spent scrolling so far |
| 47 | timeElapsed = timeCurrent - timeStart |
| 48 | |
| 49 | // calculate next scroll position |
| 50 | next = easing(timeElapsed, start, distance, duration) |
| 51 | |
| 52 | // scroll to it |
| 53 | window.scrollTo(0, next) |
| 54 | |
| 55 | // check progress |
| 56 | timeElapsed < duration |
| 57 | ? window.requestAnimationFrame(loop) // continue scroll loop |
| 58 | : done() // scrolling is done |
| 59 | } |
| 60 | |
| 61 | // scroll finished helper |
| 62 | |