-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
24 lines (19 loc) · 830 Bytes
/
index.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
const modal = document.querySelector(".modal");
const directionsButton = document.querySelector(".directions-button");
const closeButton = document.querySelector(".close-button");
// Function to show modal.
toggleModal = () => {
modal.classList.toggle("show-modal");
};
// Function for the modal to be hidden when clicking outside the modal.
windowOnClick = (event) => {
if (event.target === modal) {
toggleModal();
}
};
// Event listener for the modal to show when the directions button is clicked.
directionsButton.addEventListener("click", toggleModal);
// Event listener for the modal to be hidden when the close button is clicked.
closeButton.addEventListener("click", toggleModal);
// Event listener for the modal to be hidden when clicking outside the modal.
window.addEventListener("click", windowOnClick);