diff --git a/client/src/components/netflix-grid.tsx b/client/src/components/netflix-grid.tsx index c708729..1f036e7 100644 --- a/client/src/components/netflix-grid.tsx +++ b/client/src/components/netflix-grid.tsx @@ -1,4 +1,4 @@ -import { useState, useRef, useEffect, useMemo } from "react"; +import { useState, useRef, useEffect, useMemo, useCallback } from "react"; import { useLocation } from "wouter"; import { type Video } from "@shared/schema"; import VideoCard from "./video-card"; @@ -270,10 +270,16 @@ function CategoryRow({ category, onVideoClick, hideScrollButtons = false }: Cate const isMobile = window.innerWidth < 768; if (isMobile) { - // On mobile, one full card at a time - snap to exact position + // On mobile, calculate which card is most visible const cardWidth = containerWidth - 24; // Account for container margins (12px each side) - const newIndex = Math.round(scrollLeft / cardWidth); - setCurrentIndex(Math.min(Math.max(newIndex, 0), 9)); // Ensure 0-9 range + const scrollProgress = scrollLeft / cardWidth; + const newIndex = Math.round(scrollProgress); + const clampedIndex = Math.min(Math.max(newIndex, 0), 9); // Ensure 0-9 range + + // Only update if index actually changed to prevent flickering + if (clampedIndex !== currentIndex) { + setCurrentIndex(clampedIndex); + } } } }; @@ -422,10 +428,10 @@ function CategoryRow({ category, onVideoClick, hideScrollButtons = false }: Cate setCurrentIndex(index); } }} - className={`rounded-full transition-all duration-200 ease-out ${ + className={`rounded-full transition-colors duration-300 ease-in-out ${ index === currentIndex ? 'bg-gradient-to-r from-purple-500 to-blue-500' - : 'bg-white/20 hover:bg-white/30' + : 'bg-white/25 hover:bg-white/40' }`} style={{ width: '8px',