Minimalist Scroll To Top Button - MeggiTools
Run
Toggle Theme
Share Link
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Minimalist Scroll-to-Top Button</title> <style> body { font-family: 'Arial', sans-serif; margin: 0; padding: 0; min-height: 2000px; background: #2c3e50; } .scroll-to-top { position: fixed; bottom: 20px; right: 20px; width: 40px; height: 40px; background-color: #34495e; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 18px; color: #fff; cursor: pointer; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); transition: background-color 0.3s, transform 0.3s; z-index: 1000; } .scroll-to-top:hover { background-color: #2c3e50; } .scroll-to-top:active { background-color: #34495e; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); } .scroll-to-top-icon { animation: pulse 1s infinite; } @keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } } </style> </head> <body> <div class="scroll-to-top" id="scrollToTopBtn"> <span class="scroll-to-top-icon">↑</span> </div> <script> const scrollToTopBtn = document.getElementById('scrollToTopBtn'); const rootElement = document.documentElement; function handleScroll() { const scrollTotal = rootElement.scrollHeight - rootElement.clientHeight; if ((rootElement.scrollTop / scrollTotal) > 0.20) { scrollToTopBtn.style.opacity = '1'; scrollToTopBtn.style.visibility = 'visible'; } else { scrollToTopBtn.style.opacity = '0'; scrollToTopBtn.style.visibility = 'hidden'; } } function scrollToTop() { rootElement.scrollTo({ top: 0, behavior: "smooth" }); } scrollToTopBtn.addEventListener('click', scrollToTop); document.addEventListener('scroll', handleScroll); </script> </body> </html>