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

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

              
                <p><strong>Scroll down to the box to trigger the animation!</strong></p>

<div id="box"></div>
              
            
!

CSS

              
                html, body {
  font-family: Roboto, sans-serif;
}

p {
  text-align: center;
  position: absolute;
  left: 0;
  top: 50%;
  width: 100%;
  transform: translateY(-50%);
  font-size: 1.3em;
}

#box {
  height: 200px;
  width: 200px;
  background-color: cornflowerblue;
  margin: 1000px auto 100px;
}

.animate {
  animation: animate .3s ease-in-out forwards;
}

@keyframes animate {
  from {
    background-color: cornflowerblue;
    border-radius: 0;
  }
  to {
    background-color: green;
    border-radius: 100px;
  }
}
              
            
!

JS

              
                // get the element to animate
var element = $('#box');

// check if element is in view
function inView() {
  // get window height
  var windowHeight = $(window).height();
  
  // get current scroll position (distance from the top of the page to the bottom of the current viewport)
  var scrollPosition = $(window).scrollTop() + windowHeight;
  // get element position (distance from the top of the page to the bottom of the element)
  var elementPosition = element.offset().top + element.height();
  
  // is scroll position greater than element position? (is element in view?)
  if (scrollPosition > elementPosition) {
    return true;
  }
  
  return false;
}

// listen for scroll event
$(document).on('scroll', function() {
  // execute this on scroll, is element in view?
  if (inView()) {
      // element is in view, add class to element
      element.addClass('animate');
  }
});


              
            
!
999px

Console