-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (34 loc) · 1.22 KB
/
index.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
/* -----------------------------------------
Have focus outline only for keyboard users
---------------------------------------- */
const handleFirstTab = (e) => {
if(e.key === 'Tab') {
document.body.classList.add('user-is-tabbing')
window.removeEventListener('keydown', handleFirstTab)
window.addEventListener('mousedown', handleMouseDownOnce)
}
}
const handleMouseDownOnce = () => {
document.body.classList.remove('user-is-tabbing')
window.removeEventListener('mousedown', handleMouseDownOnce)
window.addEventListener('keydown', handleFirstTab)
}
window.addEventListener('keydown', handleFirstTab)
const backToTopButton = document.querySelector(".back-to-top");
let isBackToTopRendered = false;
let alterStyles = (isBackToTopRendered) => {
backToTopButton.style.visibility = isBackToTopRendered ? "visible" : "hidden";
backToTopButton.style.opacity = isBackToTopRendered ? 1 : 0;
backToTopButton.style.transform = isBackToTopRendered
? "scale(1)"
: "scale(0)";
};
window.addEventListener("scroll", () => {
if (window.scrollY > 700) {
isBackToTopRendered = true;
alterStyles(isBackToTopRendered);
} else {
isBackToTopRendered = false;
alterStyles(isBackToTopRendered);
}
});