-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript-mp.js
77 lines (71 loc) · 2.29 KB
/
script-mp.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
69
70
71
72
73
74
75
76
77
// Media query for desktop, from 790px
const mediaQuery = window.matchMedia("(min-width: 790px)");
function handleViewportChange(e) {
if (e.matches) {
const filmDetailCollapsible = document.querySelectorAll(
".column-details .collapsible-content"
);
filmDetailCollapsible.forEach((collapsible) => {
collapsible.classList.add("expanded");
});
} else {
const filmDetailCollapsible = document.querySelectorAll(
".column-details .collapsible-content"
);
filmDetailCollapsible.forEach((collapsible) => {
collapsible.classList.remove("expanded");
});
// Slider arrow buttons
const filmStillsArrowRight = document.querySelector(
".column-images .arrow.right"
);
const filmStillsArrowLeft = document.querySelector(
".column-images .arrow.left"
);
// Slider arrow buttons-->Right arrow
filmStillsArrowRight.addEventListener("click", () => {
// Viewport width
const viewportWidth = Math.max(
document.documentElement.clientWidth || 0,
window.innerWidth || 0
);
document.querySelector(".column-images .slider-slides").scrollLeft +=
viewportWidth;
});
// Slider arrow buttons-->Left arrow
filmStillsArrowLeft.addEventListener("click", () => {
// Viewport width
const viewportWidth = Math.max(
document.documentElement.clientWidth || 0,
window.innerWidth || 0
);
document.querySelector(".column-images .slider-slides").scrollLeft -=
viewportWidth;
});
}
}
// Register the listener
mediaQuery.addEventListener("change", handleViewportChange);
// Initial check
handleViewportChange(mediaQuery);
// Collapsible sections
const collapsibleTitles = document.querySelectorAll(".column-details h2");
collapsibleTitles.forEach((title) => {
title.addEventListener("click", () => {
if (!mediaQuery.matches) {
title.classList.toggle("expanded");
const content = title.nextElementSibling;
content.classList.toggle("expanded");
}
});
});
// Mouse over .book-btns
const bookBtns = document.querySelectorAll(".book-btn");
bookBtns.forEach((btn) => {
btn.addEventListener("mouseover", () => {
btn.classList.add("hover");
});
btn.addEventListener("mouseout", () => {
btn.classList.remove("hover");
});
});