| 63 | } |
| 64 | |
| 65 | function animateScrollTo (element, to, duration) { |
| 66 | const start = element.scrollTop |
| 67 | const change = to - start |
| 68 | let currentTime = 0 |
| 69 | const increment = 20 // Equal to line-height |
| 70 | |
| 71 | const animate = function () { |
| 72 | currentTime += increment |
| 73 | const val = Math.easeInOutQuad(currentTime, start, change, duration) |
| 74 | element.scrollTop = val |
| 75 | if (!left.reader.active) left.stats.on_scroll() |
| 76 | if (currentTime < duration) { |
| 77 | requestAnimationFrame(animate, increment) |
| 78 | } |
| 79 | } |
| 80 | requestAnimationFrame(animate) |
| 81 | } |
| 82 | |
| 83 | // t = current time |
| 84 | // b = start value |