mirror of
https://github.com/andwati/andwati.com.git
synced 2026-11-11 03:15:13 +00:00
switched theme
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const scrollToTopBtn = document.getElementById('scroll-to-top');
|
||||
|
||||
if (!scrollToTopBtn) return;
|
||||
|
||||
// Show button when scrolled down 400px
|
||||
const toggleVisibility = () => {
|
||||
if (window.scrollY > 400) {
|
||||
scrollToTopBtn.classList.add('visible');
|
||||
} else {
|
||||
scrollToTopBtn.classList.remove('visible');
|
||||
}
|
||||
};
|
||||
|
||||
// Smooth scroll to top when clicked
|
||||
scrollToTopBtn.addEventListener('click', () => {
|
||||
window.scrollTo({
|
||||
top: 0,
|
||||
behavior: 'smooth',
|
||||
});
|
||||
});
|
||||
|
||||
// Throttle the scroll event listener a tiny bit for performance
|
||||
let isTicking = false;
|
||||
window.addEventListener('scroll', () => {
|
||||
if (!isTicking) {
|
||||
window.requestAnimationFrame(() => {
|
||||
toggleVisibility();
|
||||
isTicking = false;
|
||||
});
|
||||
isTicking = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user