Spaces:
Sleeping
Sleeping
File size: 1,559 Bytes
f34a8a6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | document.addEventListener("DOMContentLoaded", () => {
// Precargar todas las imágenes
const preloadImages = () => {
const images = document.querySelectorAll('.miniature');
images.forEach(img => {
// Establecer un evento para cuando la imagen cargue
img.onload = function() {
// Cuando la imagen cargue, actualiza la altura del contenedor
const toggleContent = img.closest('.toggle-content');
if (toggleContent && toggleContent.classList.contains('show')) {
toggleContent.style.maxHeight = toggleContent.scrollHeight + "px";
}
};
// Si la imagen ya está cargada (desde caché)
if (img.complete) {
img.onload();
}
});
};
// Llamar a precargar imágenes
preloadImages();
// Manejar los botones de toggle
document.querySelectorAll(".toggle-button").forEach(button => {
button.addEventListener("click", function () {
const content = this.nextElementSibling;
if (content.classList.contains("show")) {
content.style.maxHeight = null;
content.classList.remove("show");
} else {
setTimeout(() => {
content.style.maxHeight = content.scrollHeight + "px";
}, 10);
content.classList.add("show");
}
});
});
}); |