diff options
author | Aubrey Li <Aubrey-Li> | 2022-04-05 16:17:51 -0400 |
---|---|---|
committer | Aubrey Li <Aubrey-Li> | 2022-04-05 16:17:51 -0400 |
commit | 4cb2fc6f0a173939b5ee51ff2d6548058799facd (patch) | |
tree | 2f6aa087c2b2eaf51a03fc30548371afbabc2855 /src/Utils.ts | |
parent | 9a35bde069a28f53b4ecf668a066d7c94e63cce2 (diff) | |
parent | 8f6a065c192c091393e654bdac682c285a63ad8f (diff) |
merge master
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 d0d891f77..b280badd7 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; |