Repository navigation
Expand file tree
/
Copy pathscripts.js
More file actions
59 lines (50 loc) · 1.85 KB
/
Copy pathscripts.js
File metadata and controls
59 lines (50 loc) · 1.85 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
// Mobile Navigation Toggle
document.querySelector('.hamburger').addEventListener('click', function() {
document.querySelector('.nav-links').classList.toggle('active');
});
// Smooth Scrolling for Anchor Links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
if (targetId === '#') return;
const targetElement = document.querySelector(targetId);
if (targetElement) {
window.scrollTo({
top: targetElement.offsetTop - 80,
behavior: 'smooth'
});
// Close mobile menu if open
document.querySelector('.nav-links').classList.remove('active');
}
});
});
// Sticky Navbar on Scroll
window.addEventListener('scroll', function() {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.boxShadow = 'none';
}
});
// Animation on Scroll
function animateOnScroll() {
const elements = document.querySelectorAll('.service-card');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, { threshold: 0.1 });
elements.forEach(element => {
element.style.opacity = '0';
element.style.transform = 'translateY(20px)';
element.style.transition = 'all 0.6s ease';
observer.observe(element);
});
}
// Initialize animations when DOM is loaded
document.addEventListener('DOMContentLoaded', animateOnScroll);