x
This commit is contained in:
1 parent
62dec90f82
commit
9aea635e64
2 files changed
+12
-12
No files matched your search
@@ -13,15 +13,15 @@ export default function ProductGallery({ productName, categoryName, images }: Pr
|
||||
const [activeIndex, setActiveIndex] = useState(0)
|
||||
const scrollRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const handleThumbnailClick = (idx: number) => {
|
||||
setActiveIndex(idx)
|
||||
if (scrollRef.current) {
|
||||
const container = scrollRef.current
|
||||
const child = container.children[activeIndex] as HTMLElement
|
||||
const child = scrollRef.current.children[idx] as HTMLElement
|
||||
if (child) {
|
||||
container.scrollTo({ left: child.offsetLeft, behavior: 'smooth' })
|
||||
scrollRef.current.scrollTo({ left: child.offsetLeft, behavior: 'smooth' })
|
||||
}
|
||||
}
|
||||
}, [activeIndex])
|
||||
}
|
||||
|
||||
const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
|
||||
const container = e.currentTarget
|
||||
@@ -65,7 +65,7 @@ export default function ProductGallery({ productName, categoryName, images }: Pr
|
||||
<button
|
||||
key={idx}
|
||||
type="button"
|
||||
onClick={() => setActiveIndex(idx)}
|
||||
onClick={() => handleThumbnailClick(idx)}
|
||||
className={`relative aspect-square w-20 md:w-full flex-none overflow-hidden rounded-2xl border-2 transition-all snap-center ${
|
||||
activeIndex === idx ? 'border-brand-primary opacity-100' : 'border-transparent opacity-60 hover:opacity-100'
|
||||
}`}
|
||||
|
||||
Reference in new issue
Block a user