2022-01-04 18:31:13 -07:00

25 lines
681 B
JavaScript

// Current year in footer
const currentYear = new Date().getFullYear();
document.querySelector('#year').innerHTML = currentYear;
// To-top button
const toTopButton = document.querySelector('#to-top-button');
const scrollFunction = () => {
if (document.body.scrollTop > 400 || document.documentElement.scrollTop > 400) {
toTopButton.style.display = 'block';
} else {
toTopButton.style.display = 'none';
}
};
const topFunction = () => {
document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
};
toTopButton.addEventListener('click', topFunction);
window.onscroll = () => {
scrollFunction();
};