-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
69 lines (57 loc) · 1.62 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
const menuTrigger = document.querySelector('.js-trigger')
if (menuTrigger) {
const header = document.querySelector('header')
const headerLinks = [...header.querySelectorAll('a')]
menuTrigger.addEventListener('click', () => {
header.classList.toggle('is-active')
})
if (headerLinks) {
headerLinks.forEach(link => {
link.addEventListener('click', () => {
header.classList.remove('is-active')
})
})
}
}
let radiiVal = 0.5;
let maxRadius = window.innerWidth > 750 ? 1.5 : 1;
// 🤡
const lerp = (start, end, amt) => {
return (1-amt)*start+amt*end
}
const animateRadiiIn = () => {
radiiVal = radiiVal + lerp(0, maxRadius - 0.5, 0.02)
if (radiiVal < maxRadius) {
document.querySelector('body').style.setProperty('--radius', `${radiiVal}rem`);
} else {
return;
}
window.requestAnimationFrame(animateRadiiIn)
}
window.requestAnimationFrame(animateRadiiIn)
// Scrolling functions
const fixedButton = document.querySelector('.fixed-button')
const delta = 5
let scrolled
let lastItem
let lastScrollTop = 0
let scrollDistance = 100
window.addEventListener('scroll', () => {
scrolled = true
})
setInterval(() => {
if (scrolled) {
scrollHandler()
scrolled = false
}
}, 250)
function scrollHandler() {
const scrollTop = window.scrollY || document.documentElement.scrollTop
if (Math.abs(lastScrollTop - scrollTop) <= delta) return
if (scrollTop > lastScrollTop && scrollTop > scrollDistance) {
fixedButton.classList.add('is-down')
} else if (scrollTop < lastScrollTop) {
fixedButton.classList.remove('is-down')
}
lastScrollTop = scrollTop <= 0 ? 0 : scrollTop
}