-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
66 lines (58 loc) · 2.42 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
// Observer for .scene-text-container
const textObserver = new IntersectionObserver(function(entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting && !entry.target.classList.contains('showTextAnimation')) {
entry.target.classList.add('showTextAnimation');
}
});
}, { threshold: 0.3 });
// Observer for .background-plants-right
const plantObserverRight = new IntersectionObserver(function(entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting && !entry.target.classList.contains('showPlantRightAnimation')) {
entry.target.classList.add('showPlantRightAnimation');
}
});
});
// Observer for .background-plants-left
const plantObserverLeft = new IntersectionObserver(function(entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting && !entry.target.classList.contains('showPlantLeftAnimation')) {
entry.target.classList.add('showPlantLeftAnimation');
}
});
});
// Observer for .fish-blue
const fishBlueObserverRight = new IntersectionObserver(function(entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting && !entry.target.classList.contains('animate-fish-right')) {
entry.target.classList.add('animate-fish-right');
}
});
});
// Observer for .fish-black-left
const fishBlackObserverLeft = new IntersectionObserver(function(entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting && !entry.target.classList.contains('animate-fish-left')) {
entry.target.classList.add('animate-fish-left');
}
});
});
// Observer for .fish-black-right
const fishBlackObserverRight = new IntersectionObserver(function(entries, observer) {
entries.forEach(entry => {
if (entry.isIntersecting && !entry.target.classList.contains('animate__blue-fish')) {
entry.target.classList.add('animate__blue-fish');
}
});
});
// Elements to observe
const textElements = document.querySelectorAll('.scene-text-conteiner');
const plantElementsRight = document.querySelectorAll('.background-plants-right');
const plantElementsleft = document.querySelectorAll('.background-plants-left');
const h3Element = document.querySelector('h3');
const fishBlueElementright = document.querySelector('.fish-blue');
// Add observers to elements
textElements.forEach(el => textObserver.observe(el));
plantElementsRight.forEach(el => plantObserverRight.observe(el));
plantElementsleft.forEach(el => plantObserverLeft.observe(el));