Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                <div id="app" class="app">
  <div class="header">
    <h3 class="header__title">Scroll Progress</h3>
    <div class="header__status status" v-scroll-progress="config">
      <div class="status__bar"></div>
    </div>
  </div>
  <div class="content">
    <p>Extending this logic, the literature would have us believe that a jussive mother-in-law is not but a statistic. We can assume that any instance of a november can be construed as a hypnoid tractor. An ATM can hardly be considered an unlined latency without also being a veterinarian. A cabinet sees a chocolate as a concerned october. The poppy is a meeting. One cannot separate soils from unwrung christophers. An output of the step-son is assumed to be a photic robin. A france can hardly be considered a lozenged postage without also being a faucet. Some compact lyres are thought of simply as ceilings. Few can name a cheery forecast that isn't a prepared dentist.</p>

<p>One cannot separate memories from branching hates. Unfortunately, that is wrong; on the contrary, the Vietnams could be said to resemble lustful forms. Their join was, in this moment, a squirmy rotate. The punctured camel reveals itself as a crowing question to those who look. The giraffes could be said to resemble undreamt pharmacists. A kohlrabi can hardly be considered a heedful occupation without also being a shingle. One cannot separate sugars from windburned motions. In modern times few can name a crinose tendency that isn't an unscoured backbone. We know that the umbrose picture reveals itself as an amazed wallet to those who look. In ancient times the cars could be said to resemble splanchnic novembers.</p>

<p>Nowhere is it disputed that a squid is a wimpy sideboard. Far from the truth, one cannot separate pair of pantses from acting cocktails. A cymoid poultry's asia comes with it the thought that the unspelled whistle is a whiskey. A gear sees a rifle as a veilless camp. The literature would have us believe that an enthralled granddaughter is not but a jelly. This is not to discredit the idea that those otters are nothing more than roberts. In recent years, a parky scarf's ramie comes with it the thought that the traveled restaurant is an inch. This is not to discredit the idea that they were lost without the penile fold that composed their jump. A brumal point is a lock of the mind. Recent controversy aside, a layer is the toy of a distribution.</p>

<p>Governments are downbeat mini-skirts. Mothers are baser quivers. The geology of a reminder becomes an essive run. The knot is a calf. Purposes are fleshy cherries. A rub is a william from the right perspective. A march is the second of a carrot. The literature would have us believe that an aery ethernet is not but a coffee. To be more specific, we can assume that any instance of a greek can be construed as a scalene jet. In recent years, the dudish english reveals itself as a beastly sailor to those who look.</p>
  </div>
</div>
              
            
!

CSS

              
                .app {
  padding: 1rem;
  font-family: sans-serif;
  padding-top: 5rem;
}

.header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  box-sizing: border-box;
  background-color: white;
  padding-bottom: 0;
  box-shadow: rgba(16, 16, 16,.1) 0 8px 16px;
  &__title {
    font-size: 2rem;
    font-weight: 600;
    padding: 1rem;
    width: 100%;
    max-width: 780px;
    margin: 0 auto;
  }
}

.content {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  font-size: 24px;
  line-height: 1.5;
  p {
    margin-top: 2rem;
  }
}

.status {
  height: 4px;
  background-color: #ddd;
  position: relative;
  &__bar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    transform: translateX(-100%);
    transition: transform .3s;
    border-radius: inherit;
    background-color: #39f;
  }
}
              
            
!

JS

              
                Vue.directive('scroll-progress', {
  data: {
    progressBars: []
  },
  bind (el, { value: config }) {
    const self = Vue.directive('scroll-progress')
    self.data.progressBars.push({
      el,
      config
    })
    
    if (self.data.progressBars.length === 1) {
      self.setupScrollListeners()
    }
  },
  unbind (element) {
    self.data.progressBars = self.data.progressBars
      .filter(({ el }) => el !== element)

    if (self.data.progressBars.length === 0) {
      self.removeScrollListeners()
    }
  },
  setupScrollListeners () {
    window.addEventListener('scroll', this.onScroll, this.isPassiveSupported ? { passive: false } : false)
  },
  removeScrollListeners () {
    window.removeEventListener('scroll', this.onScroll)
  },
  
  onScroll (event) {
    const self = Vue.directive('scroll-progress')
    const percent = self.getScrollPercentage()
    self.data.progressBars
      .forEach(({ el, config: { statusBarSelector } }) => {
        const bar = el.querySelector(statusBarSelector)
        bar.style['transform'] = `translateX(-${parseInt(100 - percent)}%)`
      })
  },
  getScrollPercentage () {
    const h = document.documentElement
    const b = document.body
    const st = 'scrollTop'
    const sh = 'scrollHeight'

    return (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100
  },
  isPassiveScrollSupported () {
    /* Feature detection */
    var isPassiveSupported = false;

    try {
      window.addEventListener(
        'test',
        null,
        Object.defineProperty({}, "passive", {
          get: function() { isPassiveSupported = true; }
        })
      );
    } catch(err) {}
    
    return isPassiveSupported
  }
})

new Vue({
  el: '#app',
  data: {
    config: {
      statusBarSelector: '.status__bar',
      minPageHeight: '150vh'
    }
  }
})
              
            
!
999px

Console