-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathanimation.js
More file actions
40 lines (31 loc) · 897 Bytes
/
Copy pathanimation.js
File metadata and controls
40 lines (31 loc) · 897 Bytes
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
const animatedTags = document.querySelectorAll("h2, h3, p, section img, a.button")
//fade out on load
animatedTags.forEach(tag =>{
tag.style.opacity = 0
})
const fadeIn = function (){
//look through all the animated tags and see
//with the getBoundingClientRect of it's in the window
let delay = 0.25
animatedTags.forEach(tag=>{
const tagTop = tag.getBoundingClientRect().top
const tagBottom = tag.getBoundingClientRect().bottom
if(tagTop<window.innerHeight && tagBottom > 0){
tag.style.animation = `fadein 1s ${delay}s both`
delay= delay + 0.1
}else{
tag.style.opacity = 0
tag.style.animation =""
}
})
}
//on load, run fadeIn
fadeIn()
//on scroll, run fadeIn
document.addEventListener("scroll", function(){
fadeIn()
})
//on Browser resize, run FadeIn
window.addEventListener("resize", function(){
fadeIn()
})