-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
66 lines (57 loc) · 1.61 KB
/
script.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Initialize AOS
AOS.init({
duration: 1000,
once: true,
offset: 100
});
// Navbar toggle
const navToggle = document.querySelector('.nav-toggle');
const navMenu = document.querySelector('.nav-menu');
const navLinks = document.querySelectorAll('.nav-link');
navToggle.addEventListener('click', () => {
navToggle.classList.toggle('open');
navMenu.classList.toggle('active');
});
// Close mobile menu when a nav item is clicked
navLinks.forEach(link => {
link.addEventListener('click', () => {
navToggle.classList.remove('open');
navMenu.classList.remove('active');
});
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Navbar scroll effect
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (window.scrollY > 50) {
navbar.style.padding = '0.5rem 0';
navbar.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.1)';
} else {
navbar.style.padding = '1rem 0';
navbar.style.boxShadow = 'none';
}
// Go to top button
const goToTopBtn = document.querySelector('.go-to-top');
window.addEventListener('scroll', () => {
if (window.pageYOffset > 100) {
goToTopBtn.classList.add('show');
} else {
goToTopBtn.classList.remove('show');
}
});
goToTopBtn.addEventListener('click',
(e) => {
e.preventDefault();
window.scrollTo({
top: 0, behavior: 'smooth'
});
});
});