-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
72 lines (60 loc) · 2.69 KB
/
scripts.js
File metadata and controls
72 lines (60 loc) · 2.69 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
let lastscroll = 0;
// Added scroll aware navbar
window.addEventListener('scroll', function() {
const navbar = document.querySelector('.navbar');
const currentScroll = window.scrollY;
if (window.scrollY > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
if (currentScroll > lastscroll && currentScroll > 80) {
navbar.classList.add('hide-nav');
} else {
navbar.classList.remove('hide-nav');
}
lastscroll = currentScroll;
});
// Smooth scrolling for navigation links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// FAQ Accordion functionality - Allow multiple open
document.querySelectorAll('.faq-question').forEach(button => {
button.addEventListener('click', () => {
const faqItem = button.parentElement;
// Toggle the clicked item
faqItem.classList.toggle('active');
});
});
// Dark mode toggle functionality with View Transitions
const themeToggle = document.getElementById('theme-toggle');
const htmlElement = document.documentElement;
// Check for saved theme preference or default to dark mode
const currentTheme = localStorage.getItem('theme') || 'dark';
htmlElement.setAttribute('data-theme', currentTheme);
// keep a matching class name for some transition selectors
if (currentTheme === 'dark') htmlElement.classList.add('dark');
const applyTheme = (newTheme) => {
htmlElement.setAttribute('data-theme', newTheme);
if (newTheme === 'dark') htmlElement.classList.add('dark'); else htmlElement.classList.remove('dark');
localStorage.setItem('theme', newTheme);
};
themeToggle.addEventListener('click', () => {
const cur = htmlElement.getAttribute('data-theme');
const newTheme = cur === 'light' ? 'dark' : 'light';
if (document.startViewTransition) {
document.startViewTransition(() => applyTheme(newTheme));
} else {
applyTheme(newTheme);
}
});