-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Expand file tree
/
Copy pathindex.js
More file actions
39 lines (33 loc) · 800 Bytes
/
index.js
File metadata and controls
39 lines (33 loc) · 800 Bytes
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
function init() {
const backToTopButton = document.querySelector(".jenkins-back-to-top");
if (!backToTopButton) {
return;
}
const threshold = 300;
let ticking = false;
const updateVisibility = () => {
if (window.scrollY > threshold) {
backToTopButton.classList.add("jenkins-back-to-top--visible");
} else {
backToTopButton.classList.remove("jenkins-back-to-top--visible");
}
ticking = false;
};
window.addEventListener(
"scroll",
() => {
if (!ticking) {
window.requestAnimationFrame(updateVisibility);
ticking = true;
}
},
{ passive: true },
);
backToTopButton.addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
});
}
export default { init };