<!-- in css: --> <style> #p-bar-wrapper { display:none; position: fixed; bottom: 0; right: 0; width: 100vw; height: 8px; background-color:#d1d6d8; z-index: 18; } #progress-bar { background-color:#295b71; width: 0; height: 8px; transition: .3s; } #progress-bar span { position: absolute; color: #42616c; top: -18px; font-size: 0.8em; font-weight: 600; margin-right:0; } #run-bar.right-fix { margin-right: -80px; } #run-bar.right-fix-2one { margin-right: -77px; } </style> <!-- in html: --> <div id="p-bar-wrapper"> <div id="progress-bar"><span id="run-bar"></span></div> </div> <!-- in js: --> <script src="https://code.jquery.com/jquery-3.7.1.min.js" crossorigin="anonymous"></script> <script type="text/javascript" async> document.addEventListener("DOMContentLoaded", function() { document.addEventListener("scroll", function() { var scrollTop = document.documentElement.scrollTop || document.body.scrollTop; var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight; var clientHeight = document.documentElement.clientHeight || document.body.clientHeight; var windowWidth = window.innerWidth; var p_bar = document.getElementById("progress-bar"); var scrolled = (scrollTop / (scrollHeight - clientHeight)) * 100; //Check if Tablet or smaller than hide all progress bar if( windowWidth < 767 ){ return; } else { jQuery("#p-bar-wrapper").css('display','block').show('slow'); p_bar.style.width = scrolled + "%"; var scrolled_num = parseInt(scrolled, 10); var span_run = document.getElementById("run-bar"); jQuery(span_run).text(scrolled_num + '%').css('right',scrolled + '%'); if (scrolled == 100){ jQuery(span_run).addClass('right-fix-2one').css('color','#21f1af'); } else { jQuery(span_run).removeClass('right-fix-2one').css('color','#42616c'); if (scrolled > 15){ jQuery(span_run).addClass('right-fix'); } else { jQuery(span_run).removeClass('right-fix'); } } } }); }); </script>
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