-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
179 lines (163 loc) · 6.64 KB
/
main.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
const animationFrames = [0, 0, 150, 65, 45, 22, 15, 12, 12, 12, 12, 12, 12, 12, 12, 12, 15, 18, 25, 50, 75]
const helloLinesPos = [83.5, 119.5, 149.5, 184.5, 219.5, 249.5, 279.5]
const helloLinesWait = [150, 400, 250, 125, 250, 175, 350]
const hello = "Hello!"
var helloMoved = false
const baseFirstNameLeft = 380
const baseFirstNameTop = 150
const baseLastNameLeft = 488
const baseLastNameTop = 230
window.addEventListener("load", function(event){
if(window.innerWidth >= 1000){
addAnimations()
setNamePosition()
animateName()
showStartArrow()
}
setSignGlowScroll()
setSignPosition()
setInfoSectionHeight()
})
const addAnimations = function(){
const vl = document.getElementById("vl")
vl.style.animation = "vl-expand 1s"
vl.style.animationDelay = "0.25s"
vl.style.animationFillMode = "forwards"
const profilePicture = document.getElementById("profile-picture")
profilePicture.style.animation = "picture-reveal 0.6s"
profilePicture.style.animationDelay = "0.4s"
profilePicture.style.animationFillMode = "forwards"
const description = document.getElementById("description")
description.style.animation = "description-reveal 0.4s"
description.style.animationDelay = "1s"
description.style.animationFillMode = "forwards"
const startArrow = document.getElementById("start-arrow")
startArrow.style.animation = "start-arrow-reveal 0.3s"
startArrow.style.animationDelay = "2s"
}
const setNamePosition = function(){
const frontTest = document.getElementById("test-0")
frontTest.style.left = "calc(50vw - " + (768 - (baseFirstNameLeft)).toString() + "px)"
frontTest.style.top = "calc(50vh - " + (362 - (baseFirstNameTop)).toString() + "px)"
const frontTest2 = document.getElementById("test2-0")
frontTest2.style.left = "calc(50vw - " + (768 - (baseLastNameLeft)).toString() + "px)"
frontTest2.style.top = "calc(50vh - " + (362 - (baseLastNameTop)).toString() + "px)"
for(let i = 1; i <= 20; i++){
const test = document.getElementById("test-" + i.toString())
test.style.left = "calc(50vw - " + (768 - (baseFirstNameLeft + (0.5 * (i - 1)))).toString() + "px)"
test.style.top = "calc(50vh - " + (362 - (baseFirstNameTop - (0.5 * (i - 1)))).toString() + "px)"
const test2 = document.getElementById("test2-" + i.toString())
test2.style.left = "calc(50vw - " + (768 - (baseLastNameLeft + (0.5 * (i - 1)))).toString() + "px)"
test2.style.top = "calc(50vh - " + (362 - (baseLastNameTop - (0.5 * (i - 1)))).toString() + "px)"
}
}
const animateName = function(){
animateNameNr(1, function(){})
setTimeout(function(){
animateName2Nr(1, function(){})
}, 150)
}
const animateNameNr = function(nr, callback){
if(nr <= 20){
setTimeout(function(){
const front = document.getElementById("test-0")
const test = document.getElementById("test-" + nr.toString())
test.classList.toggle("hidden")
front.style.left = "calc(50vw - " + (768 - (baseFirstNameLeft + (0.5 * (nr - 1)))).toString() + "px)"
front.style.top = "calc(50vh - " + (362 - (baseFirstNameTop - (0.5 * (nr - 1)))).toString() + "px)"
animateNameNr(nr + 1, function(){
callback()
})
}, animationFrames[nr])
}
else{
callback()
}
}
const animateName2Nr = function(nr, callback){
if(nr <= 20){
setTimeout(function(){
const front = document.getElementById("test2-0")
const test = document.getElementById("test2-" + nr.toString())
test.classList.toggle("hidden")
front.style.left = "calc(50vw - " + (768 - (baseLastNameLeft + (0.5 * (nr - 1)))).toString() + "px)"
front.style.top = "calc(50vh - " + (362 - (baseLastNameTop - (0.5 * (nr - 1)))).toString() + "px)"
animateName2Nr(nr + 1, function(){
callback()
})
}, animationFrames[nr])
}
else{
callback()
}
}
const showStartArrow = function(){
const arrow = document.getElementById("start-arrow")
setTimeout(function(){
arrow.style.opacity = "1"
arrow.style.animation = "start-arrow-mover 2s infinite"
arrow.addEventListener("click", function(event){
document.getElementById("section-2").scrollIntoView({ behavior: "smooth" })
})
}, 2300)
}
const setSignGlowScroll = function(){
window.addEventListener("scroll", function(event){
if(this.scrollY > (window.innerHeight * 0.5)){
const signGlow = document.getElementById("sign-glow")
signGlow.style.animation = "sign-glow-on 0.4s"
signGlow.style.animationDelay = "2.85s"
signGlow.style.animationFillMode = "forwards"
if(!helloMoved){
helloMoved = true
moveHelloLine(0, function(){})
revealInfo()
}
}
})
}
const moveHelloLine = function(nr, callback){
if(nr < helloLinesWait.length){
const line = document.getElementById("hello-divider")
const text = document.getElementById("hello")
setTimeout(function(){
line.style.left = "calc(33.8vw + " + helloLinesPos[nr] + "px)"
text.innerText = hello.substr(0, nr)
moveHelloLine(nr + 1, function(){
callback()
})
}, helloLinesWait[nr])
}
else{
callback()
}
}
const revealInfo = function(){
const info = document.getElementById("info-text")
info.style.animation = "info-reveal 0.5s"
info.style.animationDelay = "2s"
info.style.animationFillMode = "forwards"
}
const setSignPosition = function(){
const sign = document.getElementById("sign")
const signGlow = document.getElementById("sign-glow")
if(window.innerWidth >= 2094){
sign.style.left = "calc(33.8vw - 330.9px)"
signGlow.style.left = "calc(33.8vw - 330.9px)"
}
}
const setInfoSectionHeight = function(){
const infoText = document.getElementById("info-text")
const info = document.getElementById("info")
const section2 = document.getElementById("section-2")
const gradient = document.getElementById("gradient")
const height = infoText.clientHeight + 325
info.style.height = "calc(" + height + "px - 80px)"
section2.style.height = height + "px"
if(height < (window.innerHeight)){
gradient.style.height = "100vh"
}
else{
gradient.style.height = height + "px"
}
}