diff --git a/src/components/dashboard/Dashboard.tsx b/src/components/dashboard/Dashboard.tsx index 2882997..bfdee66 100644 --- a/src/components/dashboard/Dashboard.tsx +++ b/src/components/dashboard/Dashboard.tsx @@ -169,6 +169,7 @@ const Dashboard = () => { {newestAlbums && recentAlbums && randomAlbums && ( <> { /> { /> { /> ` overflow-x: auto; white-space: nowrap; ::-webkit-scrollbar { - height: 10px; + height: ${(props) => (props.$noScrollbar ? '0px' : '10px')}; } - - scroll-behavior: smooth; `; const ScrollingMenu = ({ @@ -26,6 +24,7 @@ const ScrollingMenu = ({ onClickTitle, type, handleFavorite, + noScrollbar, }: any) => { const cacheImages = Boolean(settings.getSync('cacheImages')); const misc = useAppSelector((state) => state.misc); @@ -35,7 +34,7 @@ const ScrollingMenu = ({ return ( <> - + 0 && ( - } onClick={() => { - scrollContainerRef.current.scrollLeft -= - config.lookAndFeel.gridView.cardSize * 5; + smoothScroll( + 400, + scrollContainerRef.current, + scrollContainerRef.current.scrollLeft - + config.lookAndFeel.gridView.cardSize * 5, + 'scrollLeft' + ); }} - /> - + + + } onClick={() => { - scrollContainerRef.current.scrollLeft += - config.lookAndFeel.gridView.cardSize * 5; + smoothScroll( + 400, + scrollContainerRef.current, + scrollContainerRef.current.scrollLeft + + config.lookAndFeel.gridView.cardSize * 5, + 'scrollLeft' + ); }} - /> + > + + )} @@ -76,14 +89,16 @@ const ScrollingMenu = ({ - + {data.map((item: any) => ( { }); } }; + +// From https://gist.github.com/andjosh/6764939#gistcomment-3564498 +const easeInOutQuad = ( + currentTime: number, + start: number, + change: number, + duration: number +): number => { + let newCurrentTime = currentTime; + newCurrentTime /= duration / 2; + + if (newCurrentTime < 1) { + return (change / 2) * newCurrentTime * newCurrentTime + start; + } + + newCurrentTime -= 1; + return (-change / 2) * (newCurrentTime * (newCurrentTime - 2) - 1) + start; +}; + +// From https://gist.github.com/andjosh/6764939#gistcomment-3564498 +export const smoothScroll = ( + duration: number, + element: HTMLElement, + to: number, + property: 'scrollTop' | 'scrollLeft' +): void => { + const start = element[property]; + const change = to - start; + const startDate = new Date().getTime(); + + const animateScroll = () => { + const currentDate = new Date().getTime(); + const currentTime = currentDate - startDate; + + element[property] = easeInOutQuad(currentTime, start, change, duration); + + if (currentTime < duration) { + requestAnimationFrame(animateScroll); + } else { + element[property] = to; + } + }; + animateScroll(); +};