forked from sumn2u/learn-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (23 loc) · 695 Bytes
/
script.js
File metadata and controls
26 lines (23 loc) · 695 Bytes
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
const openBtn = document.getElementById("openModalBtn");
const closeBtn = document.getElementById("closeModalBtn");
const modal = document.getElementById("videoModal");
const video = document.getElementById("trailer");
// Open modal
openBtn.addEventListener("click", () => {
modal.classList.add("active");
video.play();
});
// Close modal
closeBtn.addEventListener("click", () => {
modal.classList.remove("active");
video.pause();
video.currentTime = 0; // reset to beginning
});
// Close when clicking outside the video
modal.addEventListener("click", (e) => {
if (e.target === modal) {
modal.classList.remove("active");
video.pause();
video.currentTime = 0;
}
});