-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
28 lines (24 loc) · 829 Bytes
/
scripts.js
File metadata and controls
28 lines (24 loc) · 829 Bytes
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
function openModal(num){
document.getElementById('modal'+num).showModal();
}
function closeModal(num){
document.getElementById('modal'+num).close();
}
window.addEventListener('click', (event) => {
// 1. Check if the element clicked is actually a native <dialog> tag
if (event.target.tagName === 'DIALOG') {
const modal = event.target;
// 2. Find the unique inner .modal-content box inside THIS specific modal
const contentBox = modal.querySelector('.modal-content');
const rect = contentBox.getBoundingClientRect();
// 3. Run the boundary calculation
if (
event.clientX < rect.left ||
event.clientX > rect.right ||
event.clientY < rect.top ||
event.clientY > rect.bottom
) {
modal.close(); // Closes whichever unique modal was active
}
}
});