Published on 8/22/2017
Step 1
First, you should add a style block to the story (see below):
<style> #fablProgress { transition: transform 0.5s cubic-bezier(0.14, 0.52, 0.4, 0.78); top: 60px; left: 0px; width: 100%; height: 10px; position: fixed; } #fablBar { width: 0px; line-height: 0.6em; margin-top: -1px; } #greenLine { display: inline-block; z-index: 1000; width: 100%; height: 11px; background-color: green; transition: transform 5s cubic-bezier(.14,.52,.4,.78); } #scrolledPerc { display: inline-block; position: relative; float: right; width: 50px; height: 31px; background-color: darkgrey; color: white; text-align: center; line-height: 2.0em; font-size: 14.5px; font-family: proxima-nova,Proxima Nova,Helvetica Neue,Helvetica,Arial,sans-serif; border-radius: 3px; } </style>
Step 2
Add the below code snippet to make your progress bar interactive.
<script> function progress() { var scHeight = window.innerHeight; var scWidth = document.getElementById("content").offsetWidth; var elem = document.getElementById("myBar"); var scrolled; var h = document.getElementById("content").offsetHeight; var aspect; var random = 5; window.onscroll = bar; function bar() { scrolled = window.pageYOffset || document.documentElement.scrollTop; aspect = ((scrolled*scWidth)/(h-scHeight)); elem.style.width = aspect + 'px'; var per = Math.floor(aspect*100/scWidth); if (per <= 3) { document.getElementById("scrolledPerc").style.width = 0 + "px"; document.getElementById("scrolledPerc").innerHTML = ""; } else if ((4 <= per) && (per <= 100)) { document.getElementById("scrolledPerc").style.width = 50 + "px"; document.getElementById("scrolledPerc").innerHTML = per + "%"; } else if (per > 100) per = 100; } }; progress(); </script> <div id="myProgress"> <div id="myBar"> <div id="greenLine">
Step 3
That’s it, you’re done and should see green line at the top of your story.