-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallax.js
76 lines (61 loc) · 2.72 KB
/
parallax.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
67
68
69
70
71
72
73
74
75
76
const sd1 = document.querySelector('.scroll-div1');
const sd2 = document.querySelector('.scroll-div2');
const sd3 = document.querySelector('.scroll-div3');
const ed = document.querySelector('.end-div');
const welcomeDiv = document.querySelector('.welcome');
const layers = document.querySelectorAll('.lax');
window.addEventListener('scroll', () => {
// Get the current scroll position
const scrollPosition = window.scrollY;
if (scrollPosition < window.innerHeight * 0.5) {
// Calculate the parallax effect for each layer
const parallax = scrollPosition * 0.2;
// document.querySelector('.sky').style.filter = `brightness(calc(100% - ${parallax * 0.7}%))`;
document.querySelector('.abt-me').style.opacity = `calc(100% - ${parallax * 1.8}%)`;
document.querySelector('.sky').style.opacity = `calc(100% - ${parallax}%)`;
layers.forEach((layer, index) => {
const translateY = parallax * (3 - index * 0.25); // Adjust as needed
layer.style.transform = `translateY(${translateY}px)`;
});
document.querySelector('.layer1-ext').style.transform = `translateY(calc(${parallax * 3}px + 100vh))`;
document.querySelector('.layer2-ext').style.transform = `translateY(calc(${parallax * 2.5}px + 100vh))`;
const welcomeParallax = scrollPosition * 0.9;
document.querySelector('.welcome').style.transform = `translateY(calc(10% + ${welcomeParallax}px))`;
}
const r = document.querySelector('.rm'); // the one button the glitches out
console.log(r);
if (scrollPosition >= window.innerHeight * 0.5 && scrollPosition < window.innerHeight * 1.5) {
r.style.opacity = 0;
sd1.classList.add('active');
sd2.classList.remove('active');
// sd3.classList.remove('active');
// ed.classList.remove('active');
welcomeDiv.style.opacity = 0;
}
else if (scrollPosition >= window.innerHeight * 1.5 && scrollPosition < window.innerHeight * 2.5) {
sd1.classList.remove('active');
sd2.classList.add('active');
sd3.classList.remove('active');
// ed.classList.remove('active');
}
else if (scrollPosition >= window.innerHeight * 2.5 && scrollPosition < window.innerHeight * 3.5) {
// sd1.classList.remove('active');
sd2.classList.remove('active');
sd3.classList.add('active');
ed.classList.remove('active');
}
else if (scrollPosition >= window.innerHeight * 3.5) {
// sd1.classList.remove('active');
// sd2.classList.remove('active');
sd3.classList.remove('active');
ed.classList.add('active');
}
else {
r.style.opacity = 1;
sd1.classList.remove('active');
sd2.classList.remove('active');
sd3.classList.remove('active');
ed.classList.remove('active');
welcomeDiv.style.opacity = 1; // Reset the welcome div's opacity
}
});