fix(gallery): disable animation after resizing to avoid duplicate animation
This commit is contained in:
@@ -2,8 +2,13 @@
|
|||||||
import { LazyGalleryModal } from "#components";
|
import { LazyGalleryModal } from "#components";
|
||||||
import type { InternalApi } from "nitropack/types";
|
import type { InternalApi } from "nitropack/types";
|
||||||
|
|
||||||
|
// TODO: only play intro anim ONCE
|
||||||
|
// currently, if lane count changes, the animation is being replayed and it's shit
|
||||||
|
|
||||||
const images = ref<InternalApi["/api/gallery"]["get"]>([]);
|
const images = ref<InternalApi["/api/gallery"]["get"]>([]);
|
||||||
|
|
||||||
|
const resized = ref(false);
|
||||||
|
|
||||||
const scrollArea = ref();
|
const scrollArea = ref();
|
||||||
const overlay = useOverlay();
|
const overlay = useOverlay();
|
||||||
const galleryModal = overlay.create(LazyGalleryModal);
|
const galleryModal = overlay.create(LazyGalleryModal);
|
||||||
@@ -26,6 +31,7 @@ const openModal = async (index: number) => {
|
|||||||
const lanes = ref(3);
|
const lanes = ref(3);
|
||||||
|
|
||||||
const updateLanes = () => {
|
const updateLanes = () => {
|
||||||
|
const previousValue = lanes.value;
|
||||||
if (window.innerWidth < 768) {
|
if (window.innerWidth < 768) {
|
||||||
lanes.value = 1;
|
lanes.value = 1;
|
||||||
} else if (window.innerWidth < 1152) {
|
} else if (window.innerWidth < 1152) {
|
||||||
@@ -33,6 +39,10 @@ const updateLanes = () => {
|
|||||||
} else {
|
} else {
|
||||||
lanes.value = 3;
|
lanes.value = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (previousValue !== lanes.value) {
|
||||||
|
resized.value = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const { data: galleryPhotos } = await useAsyncData("gallery", () =>
|
const { data: galleryPhotos } = await useAsyncData("gallery", () =>
|
||||||
@@ -94,9 +104,15 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
v-else
|
v-else
|
||||||
class="relative overflow-hidden rounded-sm cursor-pointer gallery-item opacity-0"
|
class="relative overflow-hidden rounded-sm cursor-pointer opacity-0"
|
||||||
:class="{ 'gallery-item-down': (index % lanes) % 2 === 1 }"
|
:class="{
|
||||||
:style="{ animationDelay: `${(index % lanes) * 300}ms` }"
|
'fade-in-focus-up': (index % lanes) % 2 === 1,
|
||||||
|
'fade-in-focus-down': (index % lanes) % 2 === 0,
|
||||||
|
'no-anim': resized,
|
||||||
|
}"
|
||||||
|
:style="{
|
||||||
|
animationDelay: `${(index % lanes) * 300}ms`,
|
||||||
|
}"
|
||||||
@click="openModal(index)"
|
@click="openModal(index)"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
@@ -142,11 +158,15 @@ onUnmounted(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.gallery-item {
|
.fade-in-focus-up {
|
||||||
animation: fadeInFocusUp 4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
animation: fadeInFocusUp 4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gallery-item-down {
|
.fade-in-focus-down {
|
||||||
animation: fadeInFocusDown 4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
animation: fadeInFocusDown 4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.no-anim {
|
||||||
|
animation-duration: 0s;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user