forked from apu52/Travel_Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplore.js
28 lines (24 loc) · 951 Bytes
/
explore.js
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
let lastClickedCard = document.querySelector(".active");
// Function to handle click events
function handleClick(card) {
// Remove active classes from all cards
const panels = document.querySelectorAll(".card");
panels.forEach(panel => panel.classList.remove("active"));
// Add active class to the clicked card
card.classList.add("active");
lastClickedCard = card; // Update the reference to the last clicked card
}
// Attach click event listener to all cards
const panels = document.querySelectorAll(".card");
panels.forEach(panel => panel.addEventListener("click", () => handleClick(panel)));
// Adjust the mouseover event listener
panels.forEach(panel => {
panel.addEventListener('mouseover', () => {
lastClickedCard.classList.remove("active");
panel.classList.add('active');
});
panel.addEventListener('mouseout', () => {
panel.classList.remove('active');
lastClickedCard.classList.add("active");
});
});