-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (30 loc) · 861 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
'use strict';
const modal = document.querySelector('.modal');
const closeModal = document.querySelector('.close-modal');
const showModal = document.querySelector('.show-modal');
//Open Modal
showModal.addEventListener('click', function () {
modal.classList.remove('hidden');
showModal.classList.add('hidden');
});
//Close action
const closeAction = function () {
modal.classList.add('hidden');
showModal.classList.remove('hidden');
};
//Close Modal with button
closeModal.addEventListener('click', closeAction);
window.addEventListener('click', function (event) {
if(event.target.tagName === "MAIN"){
closeAction();
}
});
//Close Modal with ESC key
document.addEventListener('keydown', function (event) {
console.log(event)
if (event.key === 'Escape' ) {
if (!modal.classList.contains('hidden')) {
closeAction();
}
}
});