JSFiddle - React, Tailwind, and code Playground

by Eric McCormick

HTML

<progress value="0" id="progressBar">
  <div class="progress-container">
    <span class="progress-bar"></span>
  </div>
</progress>

<article>  
  <blockquote>Scroll through the page and keep an eye on the top of the webpage.</blockquote>
  
   <p>Passepartout, when he saw his master arrested, would have fallen upon Fix had he not been held back by some policemen.  Aouda was thunderstruck at the suddenness of an event which she could not understand.  Passepartout explained to her how it was that the honest and courageous Fogg was arrested as a robber.  The young woman's heart revolted against so heinous a charge, and when she saw that she could attempt to do nothing to save her protector, she wept bitterly.</p>

<p>As for Fix, he had arrested Mr. Fogg because it was his duty, whether Mr. Fogg were guilty or not.</p>

<p>The thought then struck Passepartout, that he was the cause of this new misfortune!  Had he not concealed Fix's errand from his master?  When Fix revealed his true character and purpose, why had he not told Mr. Fogg?  If the latter had been warned, he would no doubt have given Fix proof of his innocence, and satisfied him of his mistake; at least, Fix would not have continued his journey at the expense and on the heels of his master, only to arrest him the moment he set foot on English soil. Passepartout wept till he was blind, and felt like blowing his brains out.</p>

<p>Aouda and he had remained, despite the cold, under the portico of the Custom House.  Neither wished to leave the place; both were anxious to see Mr. Fogg again.</p>

<p>That gentleman was really ruined, and that at the moment when he was about to attain his end.  This arrest was fatal.  Having arrived at Liverpool at twenty minutes before twelve on the 21st of December, he had till a quarter before nine that evening to reach the Reform Club, that is, nine hours and a quarter; the journey from Liverpool to London was six hours.</p>

<p>If anyone, at this moment, had entered the...

CSS

progress {
  /* Positioning */
  position: fixed;
  left: 0;
  top: 0;
  z-index: 9999;

  /* Dimensions */
  width: 100%;
  height: .25em;

  /* Reset the apperance */  
  -webkit-appearance: none;
     -moz-appearance: none;
          appearance: none;

  /* Get rid of the default border in Firefox/Opera. */
  border: none;

  /* For Firefox/IE10+ */
  background-color: transparent;

  /* For IE10+, color of the progress bar */
  color: red;
}

progress::-webkit-progress-bar {
  background-color: transparent;
}

.flat::-webkit-progress-value {
  background-color: red;
}

.flat::-moz-progress-bar {
  background-color: red;
}

.single::-webkit-progress-value {
  background-color: transparent;
  background-image: -webkit-linear-gradient(left, transparent, red);
}

.single::-moz-progress-bar {
  background-color: transparent;
  background-image: -moz-linear-gradient(left, transparent, red);
}

.multiple::-webkit-progress-value {
  background-image: -webkit-linear-gradient(-45deg, 
	                           transparent 33%, rgba(0, 0, 0, .1) 33%, 
	                           rgba(0,0, 0, .1) 66%, transparent 66%),
	                  -webkit-linear-gradient(left, green, red);
}

.multiple::-moz-progress-bar {
  background-image: -moz-linear-gradient(-45deg, 
	                           transparent 33%, rgba(0, 0, 0, .1) 33%, 
	                           rgba(0,0, 0, .1) 66%, transparent 66%),
	                  -moz-linear-gradient(left, green, red);
}

.progress-container {
  width: 100%;
  background-color: transparent;
  position: fixed;
  top: 0;
  left: 0;
  height: .25em;
  display: block;
}

.progress-bar {
  background-color: red;
  width: 50%;
  display: block;
  height: inherit;
}

footer {
  border-top: 1px solid red;
}

JavaScript

/*
 * Modified version of:
 * http://codepen.io/pankajparashar/pen/towxF
 * 
 * Subtracts additional <footer> element's height, adds z-index to <progress> element (to prevent hiding behind images).
 */
$(document).ready(function(){
    
    var getMax = function(){
        return $(document).height() - $(window).height() - $('footer').height();
    }
    
    var getValue = function(){
        return $(window).scrollTop();
    }
    
    if('max' in document.createElement('progress')){
        // Browser supports progress element
        var progressBar = $('progress');
        
        // Set the Max attr for the first time
        progressBar.attr({ max: getMax() });

        $(document).on('scroll', function(){
            // On scroll only Value attr needs to be calculated
            progressBar.attr({ value: getValue() });
        });
      
        $(window).resize(function(){
            // On resize, both Max/Value attr needs to be calculated
            progressBar.attr({ max: getMax(), value: getValue() });
        });   
    }
    else {
        var progressBar = $('.progress-bar'), 
            max = getMax(), 
            value, width;
        
        var getWidth = function(){
            // Calculate width in percentage
            value = getValue();            
            width = (value/max) * 100;
            width = width + '%';
            return width;
        }
        
        var setWidth = function(){
            progressBar.css({ width: getWidth() });
        }
        
        $(document).on('scroll', setWidth);
        $(window).on('resize', function(){
            // Need to reset the Max attr
            max = getMax();
            setWidth();
        });
    }
});















$(document).ready(function(){
  
  $('#flat').addClass("active");
  $('#progressBar').addClass('flat');
    
  $('#flat').on('click', function(){
    $('#progressBar').removeClass().addClass('flat');
    $('a').removeClass();
   ...