-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Expand file tree
/
Copy pathscript.js
More file actions
32 lines (28 loc) · 921 Bytes
/
script.js
File metadata and controls
32 lines (28 loc) · 921 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
27
28
29
30
31
32
'use strict';
const modal = document.querySelector('.modal');
const overlay = document.querySelector('.overlay');
const btnCloseModal = document.querySelector('.close-modal');
const btnsOpenModal = document.querySelectorAll('.show-modal');
for (let index = 0; index < btnsOpenModal.length; index++)
btnsOpenModal[index].addEventListener('click', e => {
// code
// Open the modal when the corresponding button is clicked
modal.classList.remove('hidden');
overlay.classList.remove('hidden');
});
btnCloseModal.addEventListener('click', e => {
modal.classList.add('hidden');
overlay.classList.add('hidden');
// code
});
overlay.addEventListener('click', e => {
modal.classList.add('hidden');
overlay.classList.add('hidden');
// code
});
document.addEventListener('keydown', e => {
if (e.key === 'Escape') {
modal.classList.add('hidden');
overlay.classList.add('hidden');
}
});