-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimations.js
44 lines (35 loc) · 1.21 KB
/
animations.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
console.log(window.innerHeight)
function elementVisible(element){
let elementBox = element.getBoundingClientRect();
let deltaDistance = -200;
console.log(elementBox.top - window.innerHeight)
if(element.classList.contains('early')){
if(elementBox.top - window.innerHeight < deltaDistance + 250){
return true;
} else if(elementBox.top - window.innerHeight > deltaDistance + 250){
return false;
}
}
if(elementBox.top - window.innerHeight < deltaDistance){
return true;
} else if(elementBox.top - window.innerHeight > deltaDistance){
return false;
}
}
function documentScanner(){
let listSection = document.querySelectorAll('.fade-in');
let fadedSection = document.querySelectorAll('.faded')
listSection.forEach(function(section){
if(elementVisible(section)){
section.classList.remove('fade-in');
section.classList.add('faded');
}
});
fadedSection.forEach(function(section){
if(!elementVisible(section)){
section.classList.add('fade-in');
section.classList.remove('faded');
}
})
};
document.addEventListener('scroll', documentScanner)