feat(gallery): scroll to carousel current index
This commit is contained in:
@@ -170,10 +170,20 @@ const galleryModal = overlay.create(LazyGalleryModal);
|
||||
const openModal = async (image: ImageMetadata) => {
|
||||
const index = images.indexOf(image);
|
||||
if (index !== -1) {
|
||||
galleryModal.open({
|
||||
const instance = galleryModal.open({
|
||||
images,
|
||||
initialIndex: index,
|
||||
});
|
||||
|
||||
const newIndex: number = await instance.result;
|
||||
if (newIndex !== index) {
|
||||
const targetElement = document.querySelector(
|
||||
`[data-image-index="${newIndex}"]`,
|
||||
);
|
||||
if (targetElement) {
|
||||
targetElement.scrollIntoView({ behavior: "instant", block: "center" });
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -219,6 +229,7 @@ onUnmounted(() => {
|
||||
<div
|
||||
v-for="(image, idx) in getColumnImages(col)"
|
||||
:key="idx"
|
||||
:data-image-index="images.indexOf(image)"
|
||||
class="relative overflow-hidden rounded-sm bg-black cursor-pointer transition-transform"
|
||||
@click="openModal(image)"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user