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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <!-- dummy container -->
<section class="section has-background-light">
</section>
<!-- top: arrow should show past here -->
<section class="section has-background-light" id="section-top">
  <h1 class="is-size-1">Top section</h1>
  <div class="notification is-success is-light">
    <strong>Back to Top btn</strong> will show up after this section
  </div>
</section>
<!-- dummy container -->
<section class="section has-background-light section-body">
</section>
<!-- bottom: arrow should disappear past here -->
<section class="section has-background-light" id="section-bottom">
  <h1 class="is-size-1">Bottom section</h1>
  <div class="notification is-danger is-light">
    <strong>Back to Top btn</strong> will disappear before this section
  </div>
</section>
<!-- dummy container -->
<!-- dummy container -->
<section class="section has-background-light">
</section>

<!-- back to top btn -->
<a 
   href="#section-top" 
   tabindex="0" 
   id="back-to-top" 
   class="button is-primary is-rounded back-to-top" 
   data-scroll="">
    <i class="fas fa-chevron-up"></i>
</a>
              
            
!

CSS

              
                /* using Bulma and FontAwesome */

.back-to-top {
  position: fixed;
  bottom: 5vh;
  right: 5vw;
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
}


.back-to-top.visible {
    opacity: 1;
    pointer-events: all;
}

.section {
  border-bottom: 1px solid #ddd;
  min-height: 30vh;
}

.section.section-body {
  min-height: 200vh;
}

              
            
!

JS

              
                
window.addEventListener("DOMContentLoaded", function (e) {
  initBackToTopBtn();
});

function initBackToTopBtn() {
  const btn = document.querySelector("#back-to-top");
  const topSection = document.querySelector("#section-top");
  const bottomSection = document.querySelector("#section-bottom");

  window.addEventListener("scroll", function (e) {
    const topScrollTreshold =
      topSection.getBoundingClientRect().top + window.pageYOffset <
      window.pageYOffset;
    const bottomScrollTreshold =
      btn.getBoundingClientRect().top + window.pageYOffset >
      bottomSection.getBoundingClientRect().top + window.pageYOffset;

    //setting visibility based on scroll pos
    if (topScrollTreshold) {
      btn.classList.add("visible");
    } else if (btn.classList.contains("visible")) {
      btn.classList.remove("visible");
    }

    if (bottomScrollTreshold) {
      btn.classList.remove("visible");
    }
  });
}

              
            
!
999px

Console