-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
30 lines (24 loc) · 827 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
'use strict';
const showModal = document.querySelectorAll('.show-modal');
const closeModal = document.querySelector('.close-modal');
const overlay = document.querySelector('.overlay');
const modal = document.querySelector('.modal');
const addBtnModal = () => {
overlay.classList.add('hidden');
modal.classList.add('hidden');
}
const removeBtnModal = () => {
modal.classList.remove('hidden');
overlay.classList.remove('hidden');
}
for (let i = 0; i < showModal.length; i++) {
showModal[i].addEventListener('click', removeBtnModal);
}
overlay.addEventListener('click', addBtnModal);
closeModal.addEventListener('click', addBtnModal);
document.addEventListener('keydown', (e) => {
console.log(e.key);
if (e.key === 'Escape' && !modal.classList.contains('hidden')) {
addBtnModal()
}
})