From f6934de1ef650472196489f3a8cfe9c465820178 Mon Sep 17 00:00:00 2001 From: Valentin Date: Sun, 21 Apr 2024 19:15:58 +0200 Subject: [PATCH] toutes les images ne sont pas resize 6 --- user/themes/ateliers-55/js/script.js | 30 ++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/user/themes/ateliers-55/js/script.js b/user/themes/ateliers-55/js/script.js index 8356d27..80b18f5 100644 --- a/user/themes/ateliers-55/js/script.js +++ b/user/themes/ateliers-55/js/script.js @@ -73,17 +73,31 @@ function resizeVerticalImages() { let verticalImages = document.querySelectorAll('.swiper-slide > img'); let imagesIndex = 0; for (let img of verticalImages) { - imagesIndex++; - img.addEventListener('load', () => { + if(img.complete){ + imagesIndex++; if (img.clientHeight > img.clientWidth) { img.style.width = "50%"; } - }) - if (imagesIndex === verticalImages.length) { - swiperSlideEls = document.querySelectorAll('.swiper-slide'); - for (let swiperSlideEl of swiperSlideEls) { - swiperSlideEl.style.maxHeight = "unset"; + if (imagesIndex === verticalImages.length) { + swiperSlideEls = document.querySelectorAll('.swiper-slide'); + for (let swiperSlideEl of swiperSlideEls) { + swiperSlideEl.style.maxHeight = "unset"; + } } - } + } else { + img.onload = () => { + imagesIndex++; + if (img.clientHeight > img.clientWidth) { + img.style.width = "50%"; + } + if (imagesIndex === verticalImages.length) { + swiperSlideEls = document.querySelectorAll('.swiper-slide'); + for (let swiperSlideEl of swiperSlideEls) { + swiperSlideEl.style.maxHeight = "unset"; + } + } + } + } + } } \ No newline at end of file