-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
38 lines (28 loc) · 1.08 KB
/
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
37
38
'use strict';
const modalWindow = document.querySelector('.modal-window');
const overlay = document.querySelector('.overlay');
const btnCloseModalWindow = document.querySelector('.close-modal-window');
const btnsShowModalWindow = document.querySelectorAll('.show-modal-window');
console.log(btnsShowModalWindow);
const showModalWindow = function () {
console.log('Click!');
modalWindow.classList.remove('hidden');
overlay.classList.remove('hidden');
// modalWindow.style.display = 'block';
};
const closeModalWidow = function () {
modalWindow.classList.add('hidden');
overlay.classList.add('hidden');
};
for (let i = 0; i < btnsShowModalWindow.length; i++) {
console.log(btnsShowModalWindow[i].textContent);
btnsShowModalWindow[i].addEventListener('click', showModalWindow);
}
btnCloseModalWindow.addEventListener('click', closeModalWidow);
overlay.addEventListener('click', closeModalWidow);
document.addEventListener('keydown', function (event) {
console.log(event.key);
if (event.key === 'Escape' && !modalWindow.classList.contains('hidden')) {
closeModalWidow();
}
});