diff --git a/client/src/components/netflix-grid.tsx b/client/src/components/netflix-grid.tsx index baeac8e..aabf204 100644 --- a/client/src/components/netflix-grid.tsx +++ b/client/src/components/netflix-grid.tsx @@ -137,15 +137,29 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) { const scroll = (direction: 'left' | 'right') => { if (scrollRef.current) { - // Responsive scroll amount - extra small cards for Netflix style const isMobile = window.innerWidth < 768; const containerWidth = scrollRef.current.clientWidth; - // More responsive scroll amounts for better mobile experience const scrollAmount = isMobile ? containerWidth * 0.9 : containerWidth * 0.75; const currentScroll = scrollRef.current.scrollLeft; - const targetScroll = direction === 'left' - ? Math.max(0, currentScroll - scrollAmount) - : currentScroll + scrollAmount; + const maxScroll = scrollRef.current.scrollWidth - scrollRef.current.clientWidth; + + let targetScroll; + + if (direction === 'left') { + if (currentScroll <= 0) { + // If at the beginning, jump to the end (infinite loop) + targetScroll = maxScroll; + } else { + targetScroll = Math.max(0, currentScroll - scrollAmount); + } + } else { + if (currentScroll >= maxScroll - 10) { + // If at the end, jump to the beginning (infinite loop) + targetScroll = 0; + } else { + targetScroll = Math.min(maxScroll, currentScroll + scrollAmount); + } + } scrollRef.current.scrollTo({ left: targetScroll, @@ -160,10 +174,21 @@ function CategoryRow({ category, onVideoClick }: CategoryRowProps) { } scrollIntervalRef.current = setInterval(() => { if (scrollRef.current) { - const scrollAmount = direction === 'left' ? -1.5 : 1.5; - scrollRef.current.scrollLeft += scrollAmount; + const currentScroll = scrollRef.current.scrollLeft; + const maxScroll = scrollRef.current.scrollWidth - scrollRef.current.clientWidth; + const scrollAmount = direction === 'left' ? -2 : 2; + + if (direction === 'left' && currentScroll <= 0) { + // Jump to end for infinite loop + scrollRef.current.scrollLeft = maxScroll; + } else if (direction === 'right' && currentScroll >= maxScroll - 5) { + // Jump to beginning for infinite loop + scrollRef.current.scrollLeft = 0; + } else { + scrollRef.current.scrollLeft += scrollAmount; + } } - }, 8); // ~120fps for smoother animation + }, 12); // Smooth 60fps animation }; const stopAutoScroll = () => {