Back-to-Top Button auf allen Seiten hinzugefügt mit Smooth-Scroll und Fade-in/out Effekt
This commit is contained in:
25
js/main.js
25
js/main.js
@@ -194,3 +194,28 @@ document.querySelectorAll('a[href^="#"]').forEach(anchor => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Back to Top Button
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const backToTopButton = document.getElementById('back-to-top');
|
||||
|
||||
if (backToTopButton) {
|
||||
// Button bei Scroll anzeigen/verstecken
|
||||
window.addEventListener('scroll', () => {
|
||||
if (window.pageYOffset > 300) {
|
||||
backToTopButton.classList.add('show');
|
||||
} else {
|
||||
backToTopButton.classList.remove('show');
|
||||
}
|
||||
});
|
||||
|
||||
// Button Klick-Event
|
||||
backToTopButton.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
window.scrollTo({
|
||||
top: 0,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user