Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;800&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;800&display=swap" rel="stylesheet">

<div class="rpb-main">
  <div class="rp-bar">
     <div class="rp-bar-inner">
  </div>
  </div>
  <div class="rpb-header">
<h1>How to Add a Reading Progress Bar on your Shopify Blogs
</h1>
    <a class="rdc-credits" href="https://www.reddelacruz.dev/tutorials" target="blank">by rdc</a>
    <a class="bmacrdc" href="https://www.buymeacoffee.com/reddelacruzdev" target="blank">
      <img src="https://uploads-ssl.webflow.com/638ad076698caa5b223b1bc6/63e4d944f470fc036178c8bb_rdc%20red%20dela%20cruz%20buy%20me%20a%20coffee%202.png">
    </a>
  </div>
  <div class="rpb-text">
<h3>What is the lorem ipsum?</h3>
<p>Have you ever read a webpage or document that used this text without paying much attention to it? The lorem ipsum is a placeholder text used in publishing and graphic design. This filler text is a short paragraph that contains all the letters of the alphabet. The characters are spread out evenly so that the reader’s attention is focused on the layout of the text instead of its content. Many software programs and applications have made it their default dummy text. Since the lorem ipsum is always used as a placeholder text, its use indicates that this is not a final version of a document, thus helping to avoid unnecessary printing.</p>

<h3>Where does it come from?</h3>
<p>The lorem ipsum is based on De finibus bonorum et malorum, a Latin text written by Cicero in 45 BC. Typographers and printers have used passages from this work for formatting since the 16th century. Many words have been added or modified over the centuries. As a result, the lorem ipsum is no longer considered Latin, even though it looks a lot like it.</p>

<p>The lorem ipsum gets its name from the Latin phrase Neque porro quisquam est qui dolorem ipsum quia dolor sit amet. which translates to “Nor is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain.”</p>

<h3>How is it Generated?</h3>
<p>A wide range of online generators can be used to create the lorem ipsum with a single click. Here’s one to try out for your next project: https://loremipsum.io/. There’s a generator for the classic lorem ipsum, as well as for more humorous placeholder texts: hipster ipsum, zombie ipsum, pokeipsum and many more!</p>

<p>Some versions of Microsoft Word also generate the text using the =lorem() function. Just type it in your Word document and you will get this paragraph:</p>

<em>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim. Fusce est. Vivamus a tellus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Proin pharetra nonummy pede. Mauris et orci. Aenean nec lorem. In porttitor. Donec laoreet nonummy augue. Suspendisse dui purus, scelerisque at, vulputate vitae, pretium mattis, nunc. Mauris eget neque at sem venenatis eleifend. Ut nonummy.</em>

<p>Good luck on your next layout!</p>
</div>
  </div>
              
            
!

CSS

              
                * {
  margin: 0;
  font-family: 'Montserrat';
}

h1 {text-align: center}
p {margin: 20px 0}
h3 {margin-bottom: 10px}

.rpb-main,
.rpb-header {
    display: flex;
    flex-flow: column;
}

.rpb-main {
  position: relative;
  height: 100%;
  align-items: center;
  justify-content: center;
}

.rpb-header {
  background-color: #108c69;
  color: #fff;
  padding: 6% 5% 4%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 5%;
}

.rpb-text {
  width: 90%;
  max-width: 700px;
  margin-inline: auto;
}

.rp-bar {
  height: 10px;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
}

.rp-bar-inner {
    background-color: #0fcc9b;
    height: 100%;
    width: 0%;
}


.rpb-header img {
  width: 70px;
  filter: invert(1) saturate(0) brightness(1.2);
}

.rdc-credits {
  font-weight:900;
  color: #fff;
  font-size: 20px;
  margin: 40px 0 10px;
}

              
            
!

JS

              
                const bar = document.querySelector('.rp-bar-inner')
const article = document.querySelector('.rpb-main')

const moveProgressBar = function () {
  
// This means: the current Y position when you scroll divided by the height of entire article minus the height of the 'viewer'
  
// We subtracted the height of the viewer or the window itself because we don't want it to be part of the computation since that is the part that is already showing and no longer need to be scrolled.  
const yPosition = (window.scrollY) / (article.clientHeight-window.innerHeight)

// We then multiply the answer by 100 to get the percentage and that will be the width 

// Since this is a scroll event listener, it updates the width as the article scrolls
  
const barPercentage = yPosition*100
bar.style.width = `${barPercentage}%`
}

window.addEventListener('scroll', moveProgressBar)
              
            
!
999px

Console