diff options
author | mehekj <mehek.jethani@gmail.com> | 2021-11-04 16:09:13 -0400 |
---|---|---|
committer | mehekj <mehek.jethani@gmail.com> | 2021-11-04 16:09:13 -0400 |
commit | bcae1802bc5277811476ce968a337813a7841fb6 (patch) | |
tree | 783aca01ca1fb09dfc8f0804f8d663f1d1fdb5ab /src/Utils.ts | |
parent | 3ba076f93e2aa182698a229b381a77765f11213e (diff) |
smooth scroll in timeline while playing audio
Diffstat (limited to 'src/Utils.ts')
-rw-r--r-- | src/Utils.ts | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Utils.ts b/src/Utils.ts index bfb29fe8d..9faea8d60 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -514,6 +514,26 @@ export function smoothScroll(duration: number, element: HTMLElement | HTMLElemen }; animateScroll(); } + +export function smoothScrollHorizontal(duration: number, element: HTMLElement | HTMLElement[], to: number) { + const elements = (element instanceof HTMLElement ? [element] : element); + const starts = elements.map(element => element.scrollLeft); + const startDate = new Date().getTime(); + + const animateScroll = () => { + const currentDate = new Date().getTime(); + const currentTime = currentDate - startDate; + elements.map((element, i) => element.scrollLeft = easeInOutQuad(currentTime, starts[i], to - starts[i], duration)); + + if (currentTime < duration) { + requestAnimationFrame(animateScroll); + } else { + elements.forEach(element => element.scrollLeft = to); + } + }; + animateScroll(); +} + export function addStyleSheet(styleType: string = "text/css") { const style = document.createElement("style"); style.type = styleType; |