-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
77 lines (66 loc) · 2.63 KB
/
script.js
File metadata and controls
77 lines (66 loc) · 2.63 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
document.addEventListener('DOMContentLoaded', () => {
// Mobile Menu Toggle
const menuToggle = document.querySelector('.menu-toggle');
const navLinks = document.querySelector('.nav-links');
const links = document.querySelectorAll('.nav-links a');
menuToggle.addEventListener('click', () => {
navLinks.classList.toggle('active');
menuToggle.classList.toggle('active');
});
// Close menu when clicking a link
links.forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
menuToggle.classList.remove('active');
});
});
// Intersection Observer for Scroll Animations
const observerOptions = {
threshold: 0.1
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
observer.unobserve(entry.target);
}
});
}, observerOptions);
const animatedElements = document.querySelectorAll('.fade-in, .fade-in-left, .fade-in-right');
animatedElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.8s ease, transform 0.8s ease';
observer.observe(el);
});
// Smooth Scroll for Anchor Links (Backup for Safari)
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Dark Mode Toggle
const themeToggle = document.getElementById('theme-toggle');
const body = document.body;
// Check for saved theme
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
body.setAttribute('data-theme', savedTheme);
themeToggle.textContent = savedTheme === 'dark' ? '☀️' : '🌙';
}
themeToggle.addEventListener('click', () => {
if (body.getAttribute('data-theme') === 'dark') {
body.removeAttribute('data-theme');
localStorage.setItem('theme', 'light');
themeToggle.textContent = '🌙';
} else {
body.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
themeToggle.textContent = '☀️';
}
});
});