-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodal.js
51 lines (46 loc) · 1.74 KB
/
modal.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
document.addEventListener('DOMContentLoaded', () => {
// Get modal elements
const loginModal = document.getElementById('loginModal');
const signupModal = document.getElementById('signupModal');
const loginBtn = document.querySelector('button[aria-label="Login"]');
const signupBtn = document.querySelector('button[aria-label="Sign up"]');
const closeBtns = document.querySelectorAll('.close-modal');
// Open modals
loginBtn.addEventListener('click', () => {
loginModal.style.display = 'block';
document.body.style.overflow = 'hidden'; // Prevent scrolling when modal is open
});
signupBtn.addEventListener('click', () => {
signupModal.style.display = 'block';
document.body.style.overflow = 'hidden';
});
// Close modals
closeBtns.forEach((btn) => {
btn.addEventListener('click', () => {
loginModal.style.display = 'none';
signupModal.style.display = 'none';
document.body.style.overflow = 'auto';
});
});
// Close modal when clicking outside
window.addEventListener('click', (e) => {
if (e.target === loginModal || e.target === signupModal) {
loginModal.style.display = 'none';
signupModal.style.display = 'none';
document.body.style.overflow = 'auto';
}
});
// Handle form submissions
const forms = document.querySelectorAll('.modal-form');
forms.forEach((form) => {
form.addEventListener('submit', (e) => {
e.preventDefault();
// Add your form submission logic here
console.log('Form submitted:', e.target);
// Close modal after submission
loginModal.style.display = 'none';
signupModal.style.display = 'none';
document.body.style.overflow = 'auto';
});
});
});