2024-02-21 00:30:14 +01:00
|
|
|
<template>
|
|
|
|
<main>
|
|
|
|
<div class="indexImg" v-for="image in itemsAccueil" :key="image.id">
|
2024-04-06 00:46:44 +02:00
|
|
|
<img
|
2024-04-16 14:19:14 +02:00
|
|
|
:src="`/imgs/large/${image.image_accueil}.webp`"
|
2024-02-21 00:30:14 +01:00
|
|
|
:alt="image.titre"
|
2024-04-06 00:46:44 +02:00
|
|
|
/>
|
2024-02-21 00:30:14 +01:00
|
|
|
</div>
|
|
|
|
</main>
|
|
|
|
</template>
|
|
|
|
|
2024-04-06 00:46:44 +02:00
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
setup() {
|
|
|
|
const itemsAccueil = ref([]);
|
2024-02-21 00:30:14 +01:00
|
|
|
|
2024-04-12 16:14:02 +02:00
|
|
|
const { data: itemsData } = useFetch('/api/items/images_accueil', { server: true });
|
2024-04-06 00:46:44 +02:00
|
|
|
|
|
|
|
onMounted(async () => {
|
2024-04-12 16:14:02 +02:00
|
|
|
if (itemsData.value) {
|
2024-04-06 00:46:44 +02:00
|
|
|
itemsAccueil.value = itemsData.value.data;
|
2024-04-12 16:14:02 +02:00
|
|
|
setTimeout(() => {
|
|
|
|
startSlider();
|
|
|
|
}, 1);
|
2024-04-06 00:46:44 +02:00
|
|
|
}
|
|
|
|
});
|
2024-02-21 00:30:14 +01:00
|
|
|
|
2024-04-12 16:14:02 +02:00
|
|
|
|
|
|
|
|
2024-04-06 00:46:44 +02:00
|
|
|
return {
|
|
|
|
itemsAccueil,
|
|
|
|
};
|
2024-02-21 00:30:14 +01:00
|
|
|
|
|
|
|
|
2024-04-06 00:46:44 +02:00
|
|
|
function startSlider() {
|
|
|
|
const imgs = document.querySelectorAll('.indexImg img');
|
|
|
|
|
|
|
|
const showingTime = 5000, transitionTime = 2000;
|
2024-02-21 00:30:14 +01:00
|
|
|
|
2024-04-06 00:46:44 +02:00
|
|
|
for (let img of imgs) {
|
|
|
|
img.addEventListener('click', function() {
|
|
|
|
nextSlide();
|
|
|
|
resetTimer();
|
|
|
|
});
|
|
|
|
img.style.transition = `opacity ${transitionTime / 1000}s ease-out`;
|
|
|
|
}
|
2024-02-21 00:30:14 +01:00
|
|
|
|
2024-04-06 00:46:44 +02:00
|
|
|
imgs[0].style.opacity = 1;
|
2024-02-21 00:30:14 +01:00
|
|
|
|
2024-04-06 00:46:44 +02:00
|
|
|
let diapoTimer = setInterval(nextSlide, showingTime + transitionTime);
|
2024-02-21 00:30:14 +01:00
|
|
|
|
2024-04-06 00:46:44 +02:00
|
|
|
let index = 1;
|
2024-02-21 00:30:14 +01:00
|
|
|
|
2024-04-06 00:46:44 +02:00
|
|
|
function nextSlide() {
|
|
|
|
if (index === 0) {
|
|
|
|
imgs[imgs.length - 1].style.opacity = 0;
|
|
|
|
imgs[index].style.opacity = 1;
|
|
|
|
} else {
|
|
|
|
imgs[index - 1].style.opacity = 0;
|
|
|
|
imgs[index].style.opacity = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index === imgs.length - 1) {
|
|
|
|
index = 0;
|
|
|
|
} else {
|
|
|
|
index ++;
|
|
|
|
}
|
2024-02-21 00:30:14 +01:00
|
|
|
}
|
|
|
|
|
2024-04-06 00:46:44 +02:00
|
|
|
function resetTimer() {
|
|
|
|
clearInterval(diapoTimer);
|
|
|
|
diapoTimer = setInterval(nextSlide, showingTime + transitionTime);
|
|
|
|
}
|
2024-02-21 00:30:14 +01:00
|
|
|
}
|
2024-04-06 00:46:44 +02:00
|
|
|
}
|
|
|
|
};
|
2024-02-21 00:30:14 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.indexImg {
|
|
|
|
z-index: -1;
|
|
|
|
position: absolute;
|
|
|
|
overflow: hidden;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
img {
|
|
|
|
object-fit: cover;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|