From 4754f368a007d5e2d3a6eb558a79e4ee3971c9d6 Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Wed, 23 Dec 2020 09:07:08 -0500 Subject: [PATCH] Add behavior param --- src/utilities/scroll.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/utilities/scroll.ts b/src/utilities/scroll.ts index 3a558d903..39ae665ba 100644 --- a/src/utilities/scroll.ts +++ b/src/utilities/scroll.ts @@ -28,7 +28,8 @@ export function unlockBodyScrolling(lockingEl: HTMLElement) { export function scrollIntoView( element: HTMLElement, container: HTMLElement, - direction: 'horizontal' | 'vertical' | 'both' = 'vertical' + direction: 'horizontal' | 'vertical' | 'both' = 'vertical', + behavior: 'smooth' | 'auto' = 'smooth' ) { const offset = getOffset(element, container); const offsetTop = offset.top + container.scrollTop; @@ -40,17 +41,17 @@ export function scrollIntoView( if (direction === 'horizontal' || direction === 'both') { if (offsetLeft < minX) { - container.scrollTo({ left: offsetLeft, behavior: 'smooth' }); + container.scrollTo({ left: offsetLeft, behavior }); } else if (offsetLeft + element.clientWidth > maxX) { - container.scrollTo({ left: offsetLeft - container.offsetWidth + element.clientWidth, behavior: 'smooth' }); + container.scrollTo({ left: offsetLeft - container.offsetWidth + element.clientWidth, behavior }); } } if (direction === 'vertical' || direction === 'both') { if (offsetTop < minY) { - container.scrollTo({ top: offsetTop, behavior: 'smooth' }); + container.scrollTo({ top: offsetTop, behavior }); } else if (offsetTop + element.clientHeight > maxY) { - container.scrollTo({ top: offsetTop - container.offsetHeight + element.clientHeight, behavior: 'smooth' }); + container.scrollTo({ top: offsetTop - container.offsetHeight + element.clientHeight, behavior }); } } }