fix collage
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref } from "vue";
|
import { ref, onMounted, onUnmounted } from "vue";
|
||||||
|
import { Transition } from "vue";
|
||||||
|
|
||||||
const images = [
|
const images = [
|
||||||
"/img/memes/pidgeon.gif",
|
"/img/memes/pidgeon.gif",
|
||||||
@@ -9,28 +10,58 @@ const images = [
|
|||||||
"/img/bedroom/img1.png",
|
"/img/bedroom/img1.png",
|
||||||
];
|
];
|
||||||
|
|
||||||
const currentIndex = ref(1);
|
const currentIndex = ref(0);
|
||||||
|
|
||||||
function nextImage() {
|
function nextImage() {
|
||||||
currentIndex.value = Math.floor(Math.random() * 100) % images.length;
|
let newIndex;
|
||||||
|
do {
|
||||||
|
newIndex = Math.floor(Math.random() * images.length);
|
||||||
|
} while (newIndex === currentIndex.value); // prevent same image repeating
|
||||||
|
currentIndex.value = newIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(nextImage, 10000);
|
let intervalId;
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
intervalId = setInterval(nextImage, 10000);
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="image-viewer" @click="nextImage">
|
<div class="image-viewer" @click="nextImage">
|
||||||
|
<Transition name="fade" mode="out-in">
|
||||||
<img
|
<img
|
||||||
:src="images[currentIndex]"
|
:src="images[currentIndex]"
|
||||||
v-on:click="nextImage"
|
|
||||||
alt="Image Viewer"
|
alt="Image Viewer"
|
||||||
|
key="images[currentIndex]"
|
||||||
/>
|
/>
|
||||||
|
</Transition>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
.image-viewer {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
img {
|
img {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.fade-enter-active,
|
||||||
|
.fade-leave-active {
|
||||||
|
transition: opacity 0.5s ease;
|
||||||
|
}
|
||||||
|
.fade-enter-from,
|
||||||
|
.fade-leave-to {
|
||||||
|
opacity: 0;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user