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

              
                <div class="tall">
  <p>
    An example of triggering an event when the user has scrolled to the bottom of the page.
  </p>
  <p>
    As you scroll down you will notice a square that changes color and becomes a circle once you touch the bottom.
  </p>
</div>
<div class="float" id="box">
</div>
              
            
!

CSS

              
                html {
  font-family: sans-serif;
}

p {
  color: #0b3142;
  text-align: center;
  width: 80%;
  margin: auto;
  padding-top: 24px;
}

.tall {
  height: 1000px;
}

.float {
  width: 200px;
  height: 200px;
  position: absolute;
  left: 50%;
  top: 800px;
  transform: translate(-50%, -50%);
  background: #0f5257;
}

              
            
!

JS

              
                function scroller(fn) {
  var debounceTimer = null;

  function enableScroller() {
    document.addEventListener("scroll", scrollLoad);
  }

  function disableScroller() {
    document.removeEventListener("scroll", scrollLoad);
  }

  function testHeight() {
    return _testHeight();
  }

  // have we scrolled to the end of the page?
  function _testHeight() {
    return (
      window.pageYOffset + window.innerHeight >= document.body.scrollHeight
    );
  }

  // Have scrolled far enough down the page?
  function testScrollHeight() {
    if (_testHeight()) {
      disableScroller();
      fn();
      enableScroller();
    }
  }

  function scrollLoad() {
    clearTimeout(debounceTimer);
    debounceTimer = setTimeout(testScrollHeight, 100);
  }

  return {
    enableScroller,
    disableScroller,
    testHeight
  };
}

function fireWhenScrolled() {
  document.getElementById("box").style.background = "#C6B9CD";
  document.getElementById("box").style["border-radius"] = "50%";
  console.log("Bottom");
}

var activeScroller = scroller(fireWhenScrolled);
activeScroller.enableScroller();

              
            
!
999px

Console