-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs.html
48 lines (42 loc) · 1.57 KB
/
js.html
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
// Mobile Menu Toggle
const menuToggle = document.getElementById('mobile-menu');
const navMenu = document.getElementById('nav-menu');
menuToggle.addEventListener('click', function() {
navMenu.classList.toggle('show-menu');
if (navMenu.classList.contains('show-menu')) {
menuToggle.innerHTML = '<i class="fas fa-times"></i>';
} else {
menuToggle.innerHTML = '<i class="fas fa-bars"></i>';
}
});
// Smooth Scrolling
const navLinks = document.querySelectorAll('nav ul li a');
navLinks.forEach(function(link) {
link.addEventListener('click', function(e) {
e.preventDefault();
navMenu.classList.remove('show-menu');
menuToggle.innerHTML = '<i class="fas fa-bars"></i>';
const targetId = e.currentTarget.getAttribute("href") === "#" ? "header" : e.currentTarget.getAttribute("href");
const targetPosition = document.querySelector(targetId).offsetTop - 70;
window.scrollTo({
top: targetPosition,
behavior: "smooth"
});
});
});
// Contact Form Submission (Dummy Handler)
const contactForm = document.getElementById('contact-form');
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
alert('Thank you for reaching out! I will get back to you soon.');
contactForm.reset();
});
// Change Navbar Style on Scroll
window.addEventListener('scroll', function() {
const navbar = document.getElementById('navbar');
if (window.scrollY > 100) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
});