Skip to content

Commit

Permalink
Javascript update
Browse files Browse the repository at this point in the history
randomisen van de kaartjes toegevoegd
  • Loading branch information
RobbyRisse committed Sep 20, 2023
1 parent fe7b7fc commit 65c2f81
Showing 1 changed file with 34 additions and 10 deletions.
44 changes: 34 additions & 10 deletions scripts/script.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
const wrapper = document.querySelector(".wrapper");
const carousel = document.querySelector(".carousel");
const firstCardWidth = carousel.querySelector(".card").offsetWidth;
const arrowBtns = document.querySelectorAll(".wrapper button");

// Add event listeners for the arrow buttons to scroll the carousel left and right
arrowBtns.forEach(btn => {
btn.addEventListener("click", () => {
document.addEventListener("DOMContentLoaded", function() {
const wrapper = document.querySelector(".wrapper");
const carousel = document.querySelector(".carousel");
const firstCardWidth = carousel.querySelector(".card").offsetWidth;
const arrowBtns = document.querySelectorAll(".wrapper button");

// Add event listeners for the arrow buttons to scroll the carousel left and right
arrowBtns.forEach(btn => {
btn.addEventListener("click", () => {
carousel.scrollLeft += btn.id == "left" ? -firstCardWidth : firstCardWidth;
});
});
});


function randomizeItems(items) {
var cached = items.slice(0), temp, i = cached.length, rand;
while (--i) {
rand = Math.floor(Math.random() * (i + 1));
temp = cached[rand];
cached[rand] = cached[i];
cached[i] = temp;
}
return cached;
}

// Example: Call this function to randomize your card elements
function randomizeCardList() {
const cardList = document.querySelector(".carousel");
const cardItems = Array.from(cardList.querySelectorAll(".card"));
const randomizedItems = randomizeItems(cardItems);
cardList.innerHTML = ""; // Clear the existing list
randomizedItems.forEach(item => cardList.appendChild(item));
}

// Call the randomizeCardList function to randomize your card elements
randomizeCardList();
});

0 comments on commit 65c2f81

Please sign in to comment.