( element: HTMLElement | typeof window, to: number, duration = 200, callback: (element: HTMLElement | typeof window) => void = noop )
| 235 | } |
| 236 | |
| 237 | export function animatedScrollTo( |
| 238 | element: HTMLElement | typeof window, |
| 239 | to: number, |
| 240 | duration = 200, |
| 241 | callback: (element: HTMLElement | typeof window) => void = noop |
| 242 | ) { |
| 243 | const start = getScrollTop(element); |
| 244 | const change = to - start; |
| 245 | const increment = 10; |
| 246 | let currentTime = 0; |
| 247 | |
| 248 | function animateScroll() { |
| 249 | currentTime += increment; |
| 250 | const val = easeOutCubic(currentTime, start, change, duration); |
| 251 | scrollTo(element, val); |
| 252 | if (currentTime < duration) { |
| 253 | window.requestAnimationFrame(animateScroll); |
| 254 | } else { |
| 255 | callback(element); |
| 256 | } |
| 257 | } |
| 258 | animateScroll(); |
| 259 | } |
| 260 | |
| 261 | // Scroll Into View |
| 262 | // ------------------------------ |
no test coverage detected
searching dependent graphs…