Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
144 lines (121 loc) · 4.47 KB
/
Copy pathscript.js
File metadata and controls
144 lines (121 loc) · 4.47 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
document.addEventListener('DOMContentLoaded', () => {
const isHome = document.body.classList.contains('home');
const bubblesContainer = document.querySelector('.bubbles');
const bubbles = document.querySelectorAll('.bubble:not(.bubble2)');
const bubble2Elements = document.querySelectorAll('.bubble2');
let scrollPosition = window.pageYOffset;
const scrollThreshold = 300;
function parallaxScroll() {
const currentScroll = window.pageYOffset;
const scrollDiff = currentScroll - scrollPosition;
bubbles.forEach((bubble, index) => {
const speed = 0.1 + (index * 0.05);
const yOffset = -scrollDiff * speed;
const scale = Math.max(0.6, 1 - (currentScroll * 0.001));
bubble.style.transform = `translateY(${yOffset}px) scale(${scale})`;
});
if (currentScroll > scrollThreshold) {
bubble2Elements.forEach(bubble => {
bubble.classList.add('visible');
});
if (isHome && bubblesContainer) {
bubblesContainer.classList.add('scrolled');
}
} else {
bubble2Elements.forEach(bubble => {
bubble.classList.remove('visible');
});
if (isHome && bubblesContainer) {
bubblesContainer.classList.remove('scrolled');
}
}
scrollPosition = currentScroll;
}
let ticking = false;
window.addEventListener('scroll', () => {
if (!ticking) {
window.requestAnimationFrame(() => {
parallaxScroll();
ticking = false;
});
ticking = true;
}
});
parallaxScroll();
const navDots = document.querySelectorAll('.nav-dots li');
const sectionRailLabels = document.querySelectorAll('.section-rail-label');
const sections = document.querySelectorAll('.section');
const subtleNav = document.querySelector('.subtle-nav');
function usesDotNav() {
return subtleNav && (!isHome || window.innerWidth <= 768);
}
function scrollToSection(sectionId) {
const section = document.getElementById(sectionId);
if (section) {
window.scrollTo({
top: section.offsetTop - 20,
behavior: 'smooth'
});
}
}
navDots.forEach(dot => {
dot.addEventListener('click', function() {
scrollToSection(this.getAttribute('data-section'));
});
});
sectionRailLabels.forEach(label => {
label.addEventListener('click', function() {
scrollToSection(this.getAttribute('data-section'));
});
});
function updateActiveDot() {
let currentSectionId = '';
const viewportScroll = window.scrollY + window.innerHeight / 3;
if (usesDotNav() && window.scrollY > 100) {
subtleNav.classList.add('visible');
} else if (usesDotNav()) {
subtleNav.classList.remove('visible');
} else if (subtleNav) {
subtleNav.classList.remove('visible');
}
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
if (viewportScroll >= sectionTop && viewportScroll < sectionTop + sectionHeight) {
currentSectionId = section.id;
}
});
navDots.forEach(dot => {
if (dot.getAttribute('data-section') === currentSectionId) {
dot.classList.add('active');
} else {
dot.classList.remove('active');
}
});
sectionRailLabels.forEach(label => {
if (label.getAttribute('data-section') === currentSectionId) {
label.classList.add('active');
} else {
label.classList.remove('active');
}
});
}
window.addEventListener('scroll', updateActiveDot);
updateActiveDot();
window.addEventListener('resize', updateActiveDot);
let scrollTimer;
window.addEventListener('scroll', function() {
if (!usesDotNav()) {
return;
}
clearTimeout(scrollTimer);
if (window.scrollY > 100) {
subtleNav.classList.add('visible');
scrollTimer = setTimeout(function() {
if (!subtleNav.matches(':hover')) {
subtleNav.classList.remove('visible');
}
}, 1000);
}
});
});