-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
68 lines (60 loc) · 2.16 KB
/
script.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
document.addEventListener('DOMContentLoaded', function() {
let next = document.querySelector(".next");
let prev = document.querySelector(".prev");
let slide = document.querySelector(".slide");
function applyBlackAndWhiteFilter() {
let items = slide.querySelectorAll(".item");
items.forEach(item => {
item.style.filter = "grayscale(100%)";
});
}
function updateContentDisplay() {
let items = slide.querySelectorAll(".item");
items.forEach((item, index) => {
if (index === 1) {
item.querySelector(".content").style.display = "block";
item.style.filter = "grayscale(0%)"; // Show active image in color
} else {
item.querySelector(".content").style.display = "none";
item.style.filter = "grayscale(100%)"; // Apply black and white filter
}
});
}
function setupSmallImages() {
let items = slide.querySelectorAll(".item");
items.forEach((item, index) => {
if (index > 1) { // Skip the first two items (main images)
item.addEventListener("mouseenter", function() {
this.style.filter = "grayscale(0%)";
});
item.addEventListener("mouseleave", function() {
if (this !== slide.children[1]) {
this.style.filter = "grayscale(100%)";
}
});
}
});
}
next.addEventListener("click", function () {
let items = slide.querySelectorAll(".item");
slide.appendChild(items[0].cloneNode(true));
slide.removeChild(items[0]);
updateContentDisplay();
setupSmallImages(); // Reattach event listeners
});
prev.addEventListener("click", function () {
let items = slide.querySelectorAll(".item");
slide.prepend(items[items.length - 1].cloneNode(true));
slide.removeChild(items[items.length - 1]);
updateContentDisplay();
setupSmallImages(); // Reattach event listeners
});
document.addEventListener("keydown", function(e) {
if (e.key === "ArrowRight") next.click();
if (e.key === "ArrowLeft") prev.click();
});
// Initial setup
applyBlackAndWhiteFilter();
setupSmallImages();
updateContentDisplay();
});