-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
446 lines (405 loc) · 13.2 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
window.beforeunload = () => {
window.scrollTo(0, 0)
}
function enableSubmit(token) {
document.getElementById('submit').disabled = false
}
window.onload = () => {
// document.getElementById('submit').disabled = true
document.getElementById('submit').onclick = e => {
if (!document.getElementById('check').checked) {
e.preventDefault()
e.stopPropagation()
alert('Você precisa ler e concordar com nossos termos e política de privacidade para completar o envio do formulário.')
}
}
function lerp(v0, v1, t) {
t = Math.min(1, t)
t = Math.max(0, t)
return (v0 * (1 - t)) + (v1 * t)
}
const wait = ms => () => new Promise(resolve => setTimeout(resolve, ms))
var scrollSteps = [
0,
850,
1750,
2650,
3000,
]
const initialScrollSteps = [
0,
850,
1750,
2650,
3000,
]
const ilustras = {
firstBig: document.querySelector('.animation-1'),
secondBig: document.querySelector('.animation-2'),
thirdBig: document.querySelector('.animation-3'),
fourthBig: document.querySelector('.animation-4'),
}
const towers = [
document.querySelector('.t1'),
document.querySelector('.t2'),
document.querySelector('.t3'),
document.querySelector('.t4'),
document.querySelector('.t5'),
document.querySelector('.t6'),
]
// const towersInitialXY = towers.map(tower => {
// return {
// x: parseInt(
// window
// .getComputedStyle(tower)
// .getPropertyValue('transform')
// .split(',')[4]
// ),
// y: parseInt(
// window
// .getComputedStyle(tower)
// .getPropertyValue('transform')
// .split(',')[5]
// ),
// }
// })
const towersInitialXY = [
{ x: -197, y: -74, },
{ x: -115, y: -115, },
{ x: -31, y: -158, },
{ x: 4, y: 55, },
{ x: 90, y: 2, },
{ x: 171, y: -46, },
]
const towerMiddleXY = [
{ x: -240, y: -149, },
{ x: -242, y: -324, },
{ x: 0, y: -318, },
{ x: 0, y: -137, },
{ x: 240, y: -137, },
{ x: 240, y: -320, },
]
const startY = 55
const secondY = 290
Promise.resolve()
.then(wait(500))
.then(() => {
if (window.scrollY !== 0 || window.innerWidth < 1100) { throw 0 }
ilustras.fourthBig.style.transform = `translate(0, ${startY}px)`
})
.then(wait(120))
.then(() => {
if (window.scrollY !== 0 || window.innerWidth < 1100) { throw 0 }
ilustras.thirdBig.style.transform = `translate(0, ${startY}px)`
})
.then(wait(120))
.then(() => {
if (window.scrollY !== 0 || window.innerWidth < 1100) { throw 0 }
ilustras.secondBig.style.transform = `translate(0, ${startY}px)`
})
.then(wait(120))
.then(() => {
if (window.scrollY !== 0 || window.innerWidth < 1100) { throw 0 }
ilustras.firstBig.style.transform = `translate(0, ${startY}px)`
})
.catch(() => {
scrollTriggered()
})
var thirdSquareShown = false
var secondSquareShown = false
var firstSquareShown = true
window.onscroll = scrollTriggered
var snapTimer = null
function firstSquareTest (scroll, opacity, translateY) {
if (window.innerWidth < 1100) {
return
}
firstSquareShown = !!opacity
Promise.resolve()
.then(wait(100))
.then(() => { document.querySelector('.bg1-1').style.opacity = opacity })
.then(() => { document.querySelector('.bg1-1').style.transform = `translate(${translateY}px, 0)` })
.then(wait(100))
.then(() => { document.querySelector('.bg1-2').style.opacity = opacity })
.then(() => { document.querySelector('.bg1-2').style.transform = `translate(${translateY}px, 0)` })
.then(wait(100))
.then(() => { document.querySelector('.bg1-3').style.opacity = opacity })
.then(() => { document.querySelector('.bg1-3').style.transform = `translate(${translateY}px, 0)` })
}
firstSquareTest(0, 1, 20)
function secondSquareTest (scroll, opacity, translateY) {
secondSquareShown = !!opacity
Promise.resolve()
.then(wait(100))
.then(() => { document.querySelector('.bg2-1').style.opacity = 1 })
.then(() => { document.querySelector('.bg2-1').style.transform = `translate(20px, 0)` })
.then(wait(100))
.then(() => { document.querySelector('.bg2-2').style.opacity = 1 })
.then(() => { document.querySelector('.bg2-2').style.transform = `translate(20px, 0)` })
.then(wait(100))
.then(() => { document.querySelector('.bg2-3').style.opacity = 1 })
.then(() => { document.querySelector('.bg2-3').style.transform = `translate(20px, 0)` })
}
function secondSquareTestTexts (scroll, opacity, translateY) {
Promise.resolve()
.then(wait(150 * opacity))
.then(() => { document.querySelector('.box1-3').style.opacity = opacity })
.then(() => { document.querySelector('.box1-3').style.transform = `translate(0, ${translateY}px)` })
.then(wait(150 * opacity))
.then(() => { document.querySelector('.box2-3').style.opacity = opacity })
.then(() => { document.querySelector('.box2-3').style.transform = `translate(0, ${translateY}px)` })
.then(wait(150 * opacity))
.then(() => { document.querySelector('.box3-3').style.opacity = opacity })
.then(() => { document.querySelector('.box3-3').style.transform = `translate(0, ${translateY}px)` })
}
function thirdSquareTestTexts (scroll, opacity, translateY) {
thirdSquareShown = !!opacity
Promise.resolve()
.then(wait(75))
.then(() => { document.querySelector('.box1-6').style.opacity = opacity })
.then(() => { document.querySelector('.box1-6').style.transform = `translate(0, ${opacity * 10}px)` })
.then(wait(75))
.then(() => { document.querySelector('.box2-6').style.opacity = opacity })
.then(() => { document.querySelector('.box2-6').style.transform = `translate(0, ${opacity * 10}px)` })
.then(wait(75))
.then(() => { document.querySelector('.box3-6').style.opacity = opacity })
.then(() => { document.querySelector('.box3-6').style.transform = `translate(0, ${opacity * 10}px)` })
.then(wait(75))
.then(() => { document.querySelector('.box4-6').style.opacity = opacity })
.then(() => { document.querySelector('.box4-6').style.transform = `translate(0, ${opacity * 10}px)` })
.then(wait(75))
.then(() => { document.querySelector('.box5-6').style.opacity = opacity })
.then(() => { document.querySelector('.box5-6').style.transform = `translate(0, ${opacity * 10}px)` })
.then(wait(75))
.then(() => { document.querySelector('.box6-6').style.opacity = opacity })
.then(() => { document.querySelector('.box6-6').style.transform = `translate(0, ${opacity * 10}px)` })
}
function thirdSquareTest (scroll, opacity, translateY) {
Promise.resolve()
.then(wait(100))
.then(() => { document.querySelector('.bg3-1').style.opacity = 1 })
.then(() => { document.querySelector('.bg3-1').style.transform = `translate(20px, 0)` })
.then(wait(100))
.then(() => { document.querySelector('.bg3-2').style.opacity = 1 })
.then(() => { document.querySelector('.bg3-2').style.transform = `translate(20px, 0)` })
}
function scrollTriggered () {
if (window.innerWidth < 1100) { return }
const scroll = window.scrollY
firstSquareTest(scroll, 1, 20)
if (
scroll > scrollSteps[1] - 500 &&
scroll < scrollSteps[1] + 500
) {
if (!secondSquareShown) {
secondSquareTest(scroll, 1, 20)
}
} else {
if (secondSquareShown) {
secondSquareTest(scroll, 0, 0)
}
}
if (
scroll > scrollSteps[2] - 500 &&
scroll < scrollSteps[2] + 500
) {
if (!thirdSquareShown) {
thirdSquareTest(scroll, 1, 20)
}
} else {
if (thirdSquareShown) {
thirdSquareTest(scroll, 0, 0)
}
}
if (
scroll > scrollSteps[2] - 85 &&
scroll < scrollSteps[2] + 85
) {
if (!thirdSquareShown) {
thirdSquareTestTexts(scroll, 1, 20)
}
} else {
if (thirdSquareShown) {
thirdSquareTestTexts(scroll, 0, 0)
}
}
ilustras.fourthBig.style.transition = 'none'
ilustras.thirdBig.style.transition = 'none'
ilustras.secondBig.style.transition = 'none'
ilustras.firstBig.style.transition = 'none'
if (scroll === 0) {
ilustras.fourthBig.style.transform = `translate(0, ${startY}px)`
ilustras.thirdBig.style.transform = `translate(0, ${startY}px)`
ilustras.secondBig.style.transform = `translate(0, ${startY}px)`
ilustras.firstBig.style.transform = `translate(0, ${startY}px)`
return
}
const t1 = (scroll - scrollSteps[0]) / (scrollSteps[1] - scrollSteps[0])
const t2 = (scroll - scrollSteps[1]) / (scrollSteps[2] - scrollSteps[1])
const t3 = (scroll - scrollSteps[2]) / (scrollSteps[4] - scrollSteps[2])
const t4 = (scroll - scrollSteps[3]) / (scrollSteps[4] - scrollSteps[3])
document.querySelector('.home').className =
document.querySelector('.home').className
.split(' ').filter(className => className !== 'blue-color-only').join(' ')
document.querySelector('.about').className =
document.querySelector('.about').className
.split(' ').filter(className => className !== 'blue-color-only').join(' ')
document.querySelector('.specs').className =
document.querySelector('.specs').className
.split(' ').filter(className => className !== 'blue-color-only').join(' ')
document.querySelector('.contact').className =
document.querySelector('.contact').className
.split(' ').filter(className => className !== 'blue-color-only').join(' ')
if (t4 >= 0) {
document.querySelector('.contact').className += ' blue-color-only'
}
else if (t3 >= 0) {
document.querySelector('.specs').className += ' blue-color-only'
}
else if (t2 >= 0) {
document.querySelector('.about').className += ' blue-color-only'
}
else if (t1 >= 0) {
document.querySelector('.home').className += ' blue-color-only'
}
firstAnimation(t1, t2, t3, t4)
secondAnimation(t1, t2, t3, t4)
thirdAnimation(t1, t2, t3, t4)
fourthAnimation(t1, t2, t3, t4)
animateTowers(t1, t2, t3, t4)
}
function firstAnimation (t1, t2, t3, t4) {
if (t1 < 1) {
ilustras.firstBig.style.transform = `translate(0, ${
lerp(startY, -1000, t1)
}px)`
return
}
ilustras.firstBig.style.transform = `translate(0, -1500px)`
}
function secondAnimation (t1, t2, t3, t4) {
if (t1 < 1) {
ilustras.secondBig.style.transform = `translate(0, ${
lerp(startY, secondY, t1 - 0.3 * (1 - t1) + 0.1 * (t1))
}px)`
return
}
ilustras.secondBig.style.transform = `translate(0, ${
lerp(secondY, -1500, t2)
}px)`
}
function animateTowers (t1, t2, t3, t4) {
towers.forEach((tower, index) => {
const { x, y } = towersInitialXY[index]
const { x: x2, y: y2 } = towerMiddleXY[index]
if (t1 <= 1) {
tower.style.transform = `translate(${x}px, ${
lerp(y + 10, 250 + y, t1 - 0.2 * (1 - t1) + 0.15 * (t1))
}px)`
return
}
if (t2 <= 1) {
tower.style.transform = `translate(${
lerp(x, x2, t2 - ((1-t2) * 0.5))
}px, ${
lerp(250 + y, y2, t2 - ((1-t2) * 0.13))
}px)`
return
}
tower.style.transform = `translate(${x2}px, ${
lerp(y2, -1500, t3)
}px)`
})
}
function thirdAnimation (t1, t2, t3, t4) {
if (t1 < 1) {
ilustras.thirdBig.style.transform = `translate(0, ${
lerp(startY, secondY, t1 - 0.2 * (1 - t1) + 0.15 * (t1))
}px)`
return
}
if (t2 < 1) {
ilustras.thirdBig.style.transform = `translate(0, ${
lerp(secondY, 250, t2 - 0.2 * (1 - t2) + 0.5 * (t2))
}px)`
return
}
ilustras.thirdBig.style.transform = `translate(0, ${
lerp(250, -1000, t3)
}px)`
}
function fourthAnimation (t1, t2, t3, t4) {
if (t1 < 1) {
ilustras.fourthBig.style.transform = `translate(0, ${
lerp(startY, secondY, t1 - 0.1 * (1 - t1) + 0.2 * (t1))
}px)`
return
}
if (t2 < 1) {
ilustras.fourthBig.style.transform = `translate(0, ${
lerp(secondY, 250, t2 - 0.3 * (1 - t2) + 0.05 * (t2))
}px)`
return
}
ilustras.fourthBig.style.transform = `translate(0, ${
lerp(250, -200, t3)
}px)`
}
if (window.scrollY !== 0) {
scrollTriggered()
}
var scrollingTimer;
window.addEventListener('scroll', () => {
if (window.innerWidth < 1100) {
return
}
const scroll = window.scrollY
window.clearTimeout( scrollingTimer )
scrollingTimer = setTimeout(() => {
const snap = scrollSteps.concat().reverse().find(s =>
scroll > 10 &&
s - 250 < scroll &&
s + 250 > scroll &&
s <= 2650 * parseFloat(document.body.style.zoom) &&
scroll <= 2650 * parseFloat(document.body.style.zoom)
)
if (snap) {
window.scroll({ top: snap, behavior: 'smooth'})
}
}, 66)
}, false)
// const frame = document.createElement('iframe')
// frame.src = 'https://app.pipefy.com/public/form/Gp5ojRgJ?embedded=true'
// frame.frameBorder = 0
// frame.classList = 'pipefy-form'
// document.querySelector('.bg-squares-4 .pipe').appendChild(frame)
const checkSize = e => {
if (window.innerWidth < 1100) {
document.body.style.zoom = 1
scrollSteps = initialScrollSteps
return
}
window.innerWidth
if (window.innerWidth < 1450) {
document.body.style.zoom = 0.8
scrollSteps = initialScrollSteps.map(s => s * parseFloat(document.body.style.zoom))
scrollTriggered()
return
}
document.body.style.zoom = 1
scrollSteps = initialScrollSteps
scrollTriggered()
}
window.onresize = checkSize
checkSize()
setInterval(() => {
if (
scrollY > scrollSteps[1] - 70 &&
scrollY < scrollSteps[1] + 70
) {
secondSquareTestTexts(scrollY, 1, 20)
} else {
secondSquareTestTexts(scrollY, 0, 0)
}
}, 200)
}