-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
36 lines (29 loc) · 976 Bytes
/
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
"use strict";
const modal = document.querySelector(".modal");
const btnCloseModal = document.querySelector(".close-modal");
const overlay = document.querySelector(".overlay");
const btnOpenModals = document.querySelectorAll(".show-modal");
//To open modal
function openModal() {
modal.classList.remove("hidden");
overlay.classList.remove("hidden");
}
//To show modal & overlay
for (let i = 0; i < btnOpenModals.length; i++) {
btnOpenModals[i].addEventListener("click", openModal);
}
//to close modal
function closeModal() {
modal.classList.add("hidden");
overlay.classList.add("hidden");
}
//To close modal on click of modal close icon
btnCloseModal.addEventListener("click", closeModal);
//To close modal on click on overlay
overlay.addEventListener("click", closeModal);
//To close modal on Esc keypress
document.addEventListener("keydown", function (event) {
if (event.key === "Escape" && !modal.classList.contains("hidden")) {
closeModal();
}
});