Inhaltsverzeichnis
keine Gliederung
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
min-height: 200vh; /* Damit die Seite scrollbar ist */
}
/* Nach oben Button */
.scroll-to-top {
position: fixed;
bottom: 20px;
left: 20px;
width: 50px;
height: 50px;
background-color: #007bff;
border: none;
border-radius: 50%;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
transition: all 0.3s ease;
opacity: 0;
visibility: hidden;
z-index: 1000;
}
.scroll-to-top.visible {
opacity: 1;
visibility: visible;
}
.scroll-to-top:hover {
background-color: #0056b3;
transform: translateY(-5px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
}
/* Pfeil nach oben (CSS) */
.scroll-to-top::before {
content: '';
width: 0;
height: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 15px solid white;
}
/* Responsive Anpassungen */
@media (max-width: 768px) {
.scroll-to-top {
width: 45px;
height: 45px;
bottom: 15px;
left: 15px;
}
}
@media (max-width: 480px) {
.scroll-to-top {
width: 40px;
height: 40px;
bottom: 10px;
left: 10px;
}
.scroll-to-top::before {
border-left: 8px solid transparent;
border-right: 8px solid transparent;
border-bottom: 12px solid white;
}
}
/* Demo Content */
.content {
max-width: 800px;
margin: 0 auto;
}
h1 {
color: #333;
}
p {
margin-bottom: 20px;
}
</style>
<script>
// Button Element
const scrollToTopBtn = document.getElementById('scrollToTopBtn');
// Button anzeigen/verstecken beim Scrollen
window.addEventListener('scroll', function() {
if (window.pageYOffset > 300) {
scrollToTopBtn.classList.add('visible');
} else {
scrollToTopBtn.classList.remove('visible');
}
});
// Smooth Scroll nach oben
scrollToTopBtn.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
</script>