x
This commit is contained in:
1 parent
62dec90f82
commit
9aea635e64
2 files changed
+12
-12
No files matched your search
@@ -12,15 +12,15 @@ export default function ProductImageGallery({ images, fallback, alt = 'Product I
|
||||
const [currentIndex, setCurrentIndex] = useState(0)
|
||||
const scrollRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
const handleThumbnailClick = (idx: number) => {
|
||||
setCurrentIndex(idx)
|
||||
if (scrollRef.current) {
|
||||
const container = scrollRef.current
|
||||
const child = container.children[currentIndex] 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' })
|
||||
}
|
||||
}
|
||||
}, [currentIndex])
|
||||
}
|
||||
|
||||
const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
|
||||
const container = e.currentTarget
|
||||
@@ -66,7 +66,7 @@ export default function ProductImageGallery({ images, fallback, alt = 'Product I
|
||||
<button
|
||||
key={image.id || idx}
|
||||
type="button"
|
||||
onClick={() => setCurrentIndex(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 ${
|
||||
currentIndex === idx ? 'border-pop-pink shadow-md' : 'border-transparent opacity-60 hover:opacity-100'
|
||||
}`}
|
||||
|
||||
Reference in new issue
Block a user