This commit is contained in:
parent
bdb60646d0
commit
c59f4d93dd
11 changed files with 160 additions and 120 deletions
24
assets/js/back-to-top.js
Normal file
24
assets/js/back-to-top.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
export function backToTop(){
|
||||
const btn = document.getElementById('btn--back-to-top');
|
||||
if (!btn) return;
|
||||
|
||||
let lastY = window.scrollY;
|
||||
let peakY = window.scrollY;
|
||||
|
||||
window.addEventListener('scroll', () => {
|
||||
const currentY = window.scrollY;
|
||||
|
||||
if (currentY > lastY) {
|
||||
peakY = currentY;
|
||||
btn.classList.remove('is-visible');
|
||||
} else {
|
||||
if (currentY <= 800) {
|
||||
btn.classList.remove('is-visible');
|
||||
} else if (peakY - currentY >= 200 && peakY > 600) {
|
||||
btn.classList.add('is-visible');
|
||||
}
|
||||
}
|
||||
|
||||
lastY = currentY;
|
||||
}, { passive: true });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue