forked from unstoppabledomains/decentralized-websites
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
65 lines (47 loc) · 1.72 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
//Substitute vh unit for css
function setVh() {
let cH = window.innerHeight * 0.01
document.documentElement.style.setProperty('--currentheight', `${cH}px`)
}
setVh()
window.addEventListener('resize', setVh)
//Randomize background circles
const elipsis = document.querySelector('.background')
let q = 0
while (q < elipsis.children.length) mutateBorder(elipsis.children[q++])
function mutateBorder(element) {
const v = [...new Array(4)].map(() => randomBetween(25, 50))
const [_1, _2, _3, _4] = v
const [_R1, _R2, _R3, _R4] = v.map(n => 100 - n)
const borderRadius = `${_1}% ${_R1}% ${_R2}% ${_2}% / ${_3}% ${_4}% ${_R4}% ${_R3}%`
element.style.borderRadius = borderRadius
}
function randomBetween(s, l) { return s + Math.trunc(l * Math.random()) }
//Trigger visual changes on scroll from/to initial screen
const main = document.querySelector('.main')
const body = document.querySelector('body')
let scrollCheck = null
main.addEventListener('scroll', (e) => {
if (main.children[0].getBoundingClientRect().y < window.innerHeight / -4) {
if (scrollCheck !== false) body.classList.add("onscroll")
scrollCheck = false
} else {
if (scrollCheck !== true) body.classList.remove("onscroll")
scrollCheck = true
}
}, { passive: true })
//Scroll main on wheel or touch from anywhere
window.addEventListener('wheel', (e) => {
if (e.target.closest('.main')) return
main.scrollBy(0, e.deltaY)
})
let initialTouch = null
window.addEventListener('touchstart', function (e) {
initialTouch = e.changedTouches[0]
});
window.addEventListener('touchend', function (e) {
if(e.target.closest('.onscroll')) return
if(e.target.closest('.main')) return
const diff = initialTouch.screenY - e.changedTouches[0].screenY
main.scrollBy(0, diff)
})