Rounded 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>Rounded Scroll-to-Top Button</title> <style> body { font-family: 'Helvetica', sans-serif; margin: 0; padding: 0; min-height: 2000px; background: #efefef; } .scroll-to-top { position: fixed; bottom: 30px; right: 30px; width: 60px; height: 60px; background-color: #3498db; border-radius: 30px; display: flex; justify-content: center; align-items: center; font-size: 24px; color: #fff; cursor: pointer; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3); transition: all 0.3s ease-in-out; z-index: 1000; } .scroll-to-top:hover { background-color: #2980b9; transform: scale(1.1); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); } .scroll-to-top:active { transform: scale(0.9); box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); } .scroll-to-top-icon { animation: bounce 2s infinite; } @keyframes bounce { 0%, 20%, 50%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-10px); } 60% { transform: translateY(-5px); } } </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>