diff options
author | mehekj <mehek.jethani@gmail.com> | 2022-04-12 18:11:13 -0400 |
---|---|---|
committer | mehekj <mehek.jethani@gmail.com> | 2022-04-12 18:11:13 -0400 |
commit | 82272cc4735a9da78a1c4592bdf460f1ab6e644d (patch) | |
tree | b2980350c566102048cee05d5d153d78a49a4d89 /src/Utils.ts | |
parent | b3424535cb746ff9fba35375d9abf07ba174dcf0 (diff) | |
parent | ab0e1ac6f5b21f2e10bdce428c882482a0f159b4 (diff) |
Merge branch 'inkocr-mehek' into inking-naafi-mehek
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 8d71ca6eb..8c0e8c7c0 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -521,6 +521,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; |