Upgrade the traditional "Go Up" button by incorporating a circular scroll progress indicator. This feature keeps users informed about their position on the page and offers a visually engaging navigation aid.
Position the button for easy access at the bottom-right corner of the page:
<button id="goUp" style="position:fixed;bottom:32px;right:32px;">Go Up</button>Wrap the button in a container and include elements for the progress ring. Apply the following CSS for styling and layout:
#goUpWrapper { position: fixed; bottom: 32px; right: 32px; width: 60px; height: 60px; display: flex; align-items: center; justify-content: center;}#goUp { z-index: 2; position: absolute; width: 44px; height: 44px; border-radius: 50%;}#progressRing { position: absolute; width: 60px; height: 60px; border-radius: 50%; border: 4px solid #eee; /* background ring */ box-sizing: border-box;}#progressRingFill { position: absolute; width: 60px; height: 60px; border-radius: 50%; border: 4px solid #00f; /* indicator color */ border-top-color: transparent; transform: rotate(-90deg); box-sizing: border-box; transition: stroke-dashoffset 0.2s;}<div id="goUpWrapper"> <div id="progressRing"></div> <div id="progressRingFill"></div> <button id="goUp">Go Up</button></div>Track the scroll position and update the indicator, plus enable smooth scrolling:
const goUpBtn = document.getElementById('goUp');const ringFill = document.getElementById('progressRingFill');function updateScrollIndicator() {const scrollTop = window.scrollY;const docHeight = document.documentElement.scrollHeight - window.innerHeight;const scrollPercent = docHeight ? scrollTop / docHeight : 0;const angle = scrollPercent * 360;ringFill.style.transform = `rotate(${angle - 90}deg)`;}window.addEventListener('scroll', updateScrollIndicator);goUpBtn.addEventListener('click', function() { window.scrollTo({ top: 0, behavior: 'smooth' });});