-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
124 lines (105 loc) · 3.91 KB
/
scripts.js
File metadata and controls
124 lines (105 loc) · 3.91 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// JavaScript for Bangalore Community Website
// Smooth scrolling for anchor links (e.g., navigation links)
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
function openDialog(content) {
const dialog = document.getElementById('dialog');
const overlay = document.getElementById('overlay');
dialog.querySelector('.dialog-content').innerHTML = content;
dialog.style.display = 'block';
overlay.style.display = 'block';
}
function closeDialog() {
const dialog = document.getElementById('dialog');
const overlay = document.getElementById('overlay');
dialog.style.display = 'none';
overlay.style.display = 'none';
}
// Function to toggle navigation bar background on scroll
window.onscroll = function() {
const header = document.querySelector('header');
if (window.scrollY > 50) {
header.classList.add('scrolled');
} else {
header.classList.remove('scrolled');
}
};
// Form validation for the Contact Us page
const contactForm = document.querySelector('#contact form');
if (contactForm) {
contactForm.addEventListener('submit', function(event) {
const name = document.querySelector('#name').value.trim();
const email = document.querySelector('#email').value.trim();
const message = document.querySelector('#message').value.trim();
if (!name || !email || !message) {
event.preventDefault();
alert('All fields are required!');
} else if (!validateEmail(email)) {
event.preventDefault();
alert('Please enter a valid email address.');
}
});
}
// Email validation function
function validateEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(String(email).toLowerCase());
}
// Form validation for Login page
const loginForm = document.querySelector('#login form');
if (loginForm) {
loginForm.addEventListener('submit', function(event) {
const username = document.querySelector('#username').value.trim();
const password = document.querySelector('#password').value.trim();
if (!username || !password) {
event.preventDefault();
alert('Username and password are required!');
}
});
}
// Modal functionality for the Login Page
const modalBtn = document.querySelector('.login-modal-btn');
const modal = document.querySelector('.modal');
const closeModal = document.querySelector('.close-modal');
if (modalBtn && modal && closeModal) {
modalBtn.addEventListener('click', function() {
modal.style.display = 'block';
});
closeModal.addEventListener('click', function() {
modal.style.display = 'none';
});
window.addEventListener('click', function(event) {
if (event.target === modal) {
modal.style.display = 'none';
}
});
}
// Animations on Scroll using Intersection Observer API
const faders = document.querySelectorAll('.fade-in');
const sliders = document.querySelectorAll('.slide-in');
const appearOptions = {
threshold: 0,
rootMargin: '0px 0px -150px 0px'
};
const appearOnScroll = new IntersectionObserver(function(entries, appearOnScroll) {
entries.forEach(entry => {
if (!entry.isIntersecting) {
return;
} else {
entry.target.classList.add('appear');
appearOnScroll.unobserve(entry.target);
}
});
}, appearOptions);
faders.forEach(fader => {
appearOnScroll.observe(fader);
});
sliders.forEach(slider => {
appearOnScroll.observe(slider);
});