Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion libs/blocks/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,33 @@ function handlePrevious(previousElment, elements) {
return elements[elements.length - 1];
}

function setEqualHeight(slides, slideContainer, currentActiveIndex = 0) {
async function waitImgReady(img) {
if (!img) return;

if (!img.complete) {
await new Promise((resolve) => {
img.addEventListener('load', resolve, { once: true });
});
}

if ((img.offsetHeight === 0 || img.clientHeight === 0) && img.naturalHeight) {
await new Promise((resolve) => {
const ro = new ResizeObserver(() => {
if (img.offsetHeight > 0 && img.clientHeight > 0) {
ro.disconnect();
resolve();
}
});
ro.observe(img);
});
}
}

async function setEqualHeight(slides, slideContainer, currentActiveIndex = 0) {
const allImgs = slides[0]?.querySelectorAll('picture img');
if (allImgs?.length) {
await Promise.all([...allImgs].map((img) => waitImgReady(img)));
}
const maxHeight = Math.max(...slides.map((slide) => slide.offsetHeight));
const activeSlide = slides[currentActiveIndex];
slides.forEach((slide) => {
Expand Down
Loading