Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
37 lines (30 loc) · 1.39 KB

File metadata and controls

37 lines (30 loc) · 1.39 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// Modal window is not only about CSS, JavaScript actually brings life to it.
// Here we will be implementing responsiveness of modal window.
// Selecting all the necessary classes to accomplish the task.
const modal = document.querySelector(".modal");
const overlay = document.querySelector(".overlay");
const btnCloseModal = document.querySelector(".close-modal");
const btnOpenModal = document.querySelector(".show-modal");
// Creating a function which will contain all the actions that will get executed when show-modal button is clicked.
const openModal = function(){
modal.classList.remove('hidden');
overlay.classList.remove('hidden');
};
// Creating a function which will contain all the actions that will get executed when user want to close modal window.
const closeModal = function() {
modal.classList.add('hidden');
overlay.classList.add('hidden');
};
// Making show modal button responsive
btnOpenModal.addEventListener('click',openModal);
// For closing a modal window we will be implementing 3 ways.
// 1) when users click on close button.
btnCloseModal.addEventListener('click',closeModal);
// 2) when user clicks outside of the modal window.
overlay.addEventListener('click',closeModal);
// 3) when user presses escape button from the keyborad.
document.addEventListener('keydown', function(event) {
if(event.key === "Escape" && !modal.classList.contains('hidden')){
closeModal();
}
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.