Reik
posted this
16 November 2023
Moin Christian,
das geht mit den Bordmitteln von Nicepage leider nicht.
Dies kannst du aber recht simpel mit JavaScript lösen.
Kleines Beispiel:
`
<img src="bild1.jpg" alt="Bild 1">
<img src="bild2.jpg" alt="Bild 2">
<img src="bild3.jpg" alt="Bild 3">
// Funktion zum Mischen eines Arrays (Fisher-Yates Algorithmus)
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
// Holt sich alle Bilder im Galerie-Container
const galleryContainer = document.getElementById("gallery");
const images = Array.from(galleryContainer.getElementsByTagName("img"));
// Mischt die Reihenfolge der Bilder
shuffleArray(images);
// Entfernen die Bilder aus dem Container
images.forEach((image) => {
galleryContainer.removeChild(image);
});
// fügt die gemischten Bilder wieder in den Container ein
images.forEach((image) => {
galleryContainer.appendChild(image);
});
`
Moin Christian,
das geht mit den Bordmitteln von Nicepage leider nicht.
Dies kannst du aber recht simpel mit JavaScript lösen.
Kleines Beispiel:
`
<img src="bild1.jpg" alt="Bild 1">
<img src="bild2.jpg" alt="Bild 2">
<img src="bild3.jpg" alt="Bild 3">
// Funktion zum Mischen eines Arrays (Fisher-Yates Algorithmus)
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
// Holt sich alle Bilder im Galerie-Container
const galleryContainer = document.getElementById("gallery");
const images = Array.from(galleryContainer.getElementsByTagName("img"));
// Mischt die Reihenfolge der Bilder
shuffleArray(images);
// Entfernen die Bilder aus dem Container
images.forEach((image) => {
galleryContainer.removeChild(image);
});
// fügt die gemischten Bilder wieder in den Container ein
images.forEach((image) => {
galleryContainer.appendChild(image);
});
`
Last edited 16 November 2023 by Reik