-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (31 loc) · 1.09 KB
/
script.js
File metadata and controls
39 lines (31 loc) · 1.09 KB
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
'use strict';
// classes to be modified stored in variables for easier access
const btnCloseModal = document.querySelector('.close-modal');
const btnsOpenModal = document.querySelectorAll('.show-modal');
const modal = document.querySelector('.modal');
const overlay = document.querySelector('.overlay');
// function expressions for eventListeners
const openModal = function () {
modal.classList.remove('hidden');
overlay.classList.remove('hidden');
};
const closeModal = function () {
modal.classList.add('hidden');
overlay.classList.add('hidden');
};
// adding all the eventlisteners for the buttons define in HTML
// show modal buttons
for (let i = 0; i < btnsOpenModal.length; i++) {
btnsOpenModal[i].addEventListener('click', openModal);
}
// close modal buttons & actions
// close button click event
btnCloseModal.addEventListener('click', closeModal);
// overlay click even
overlay.addEventListener('click', closeModal);
// escape key press event
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && !modal.classList.contains('hidden')) {
closeModal();
}
});