//html <div class="scroll-indicator">Scroll Position: <span id="scrollPos">0</span></div> //js const scrollPosElement = document.getElementById('scrollPos'); window.addEventListener('scroll', function() { const scrollTop = document.documentElement.scrollTop || window.pageYOffset; scrollPosElement.textContent = scrollTop; });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter