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

              
                <section class='hero is-primary is-bold is-fullheight'>
  <section class='hero-body'>
    <div class='container'>
      <h1 class='title'>Animated Back To Top Button</h1>
    <p class='subtitle'>
      This button slides in all cool like after the scrolling threshold (200) is reached. It's real neat.
    </p>
    </div>
  </section>
</section>
<section class='section'>
  <div class='columns is-centered'>
    <div class='column is-three-fifths'>
      <p>
        Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p><hr /><p>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p><hr /><p>
      Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </p>
    </div>
  </div>
</section>
<button id='btt' class='button' aria-label='Scroll back to the top of the page' title='Scroll back to the top of the page'><i class='fa fa-chevron-up'></i></button>
              
            
!

CSS

              
                #btt {
  position: fixed;
  right: 2em;
  bottom: -4em;
  transition: bottom .5s ease;
  &.is-active {
    bottom: 2em;
    transition: bottom .5s ease;
  }
}
hr {
  height: 2px;
}
              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', () => {
  //set the default state
  let scrolling = false;
  //the button
  const btt = document.getElementById('btt');
  //change the default state on scroll
  window.addEventListener('scroll', () => {
    scrolling = true;
  })
  //run event handler every 300 ms
  setInterval(() => {
    if (scrolling) {
      //reset the state var
      scrolling = false;
      
      //we already talked about all this
      var top = window.pageYOffset;
      var is_active = btt.classList.contains('is-active');
      if (top > 200 && !is_active) {
        btt.classList.add('is-active');
      } else if (top < 200 && is_active) {
        btt.classList.remove('is-active');
      }
    }
  }, 300)
  
  btt.addEventListener('click', (e) => {
    e.preventDefault();
    window.scroll({
      top: 0,
      behavior: 'smooth'
    });
  })
})
              
            
!
999px

Console