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 id="redBox">
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sit corporis dolorum sapiente cupiditate. Dolorum ut facilis, odit nihil itaque ipsa alias reiciendis quae, aperiam libero veniam nesciunt asperiores eos illum!</p>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quam pariatur aspernatur maxime beatae magnam tempora alias, temporibus dignissimos quae rerum delectus sint fugit quaerat voluptatum ea eum aliquam. Veritatis, officiis?</p>
</div>
<br><br><br><br><br><br>
<div class="awesomeSauce">
  <h2>Targetted Section</h2>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi magnam architecto aliquid earum dolorem, quibusdam voluptates debitis ipsam saepe repellendus ducimus esse voluptas quis. Error nostrum dolorum magnam expedita animi!</p>
</div>
<div>
  <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Necessitatibus debitis quibusdam voluptas sed. Delectus perferendis natus sunt fugit tempore, vero commodi voluptas minima dolore odit quam enim nulla expedita ad.</p>
</div>


              
            
!

CSS

              
                body {
  font-family:sans-serif;
}

h1 {
  margin: 5px 0;
}
h3 {
  margin:0;
  font-size:16px;
}
.demo {
  width:600px;
  height:120px;
  background-color:black;
  position:relative;
}

.box {
  width:50px;
  height:50px;
  position:relative;
  margin-bottom:2px;
}

.red {
  background-color:red;
}

.blue {
  background-color:blue;
}

.green {
  top:60px;
  left:25px;
  background-color:green;
}

.nav {
  width:600px;
  background-color:#ccc;
  text-align:right;
}

button {
  padding:10px;
  font-size:20px;
}

div{
  padding: 1em 0;
}


              
            
!

JS

              
                //***********
//setting up rAF, code from HTML5rocks
//***********
var rAF = requestAnimationFrame || mozRequestAnimationFrame || webkitRequestAnimationFrame || msRequestAnimationFrame;

//debouncing animation from trigger event and triggering only when scroll happens
var latestKnownScrollY = 0,
  ticking = false;

function onScroll() {
  latestKnownScrollY = window.scrollY;
  requestTick();
}

function requestTick() {
  if (!ticking) {
    rAF(update);
  }
  ticking = true;
}

function update() {
  // reset the tick so we can
  // capture the next onScroll
  ticking = false;
  var currentScrollY = latestKnownScrollY;

  //read window inner height property to determine appear location
  var windowHeight = window.innerHeight;
  var scrollAppearLocation = (windowHeight * 6 / 9) + currentScrollY;

  // read offset of DOM elements
  // and compare to the currentScrollY value
  // then apply some CSS classes // to the visible items

  if ($(".awesomeSauce").length) {
    addAnimationClass("awesomeSauce");
  }

  function addAnimationClass(targetName) {
    var targetObject = document.getElementsByClassName(targetName)[0];
    var targetObjectOffsetTop = targetObject.offsetTop;

    //debug positioning
    console.log('scrollAppearLocation = ' + scrollAppearLocation);
    console.log('targetObjectOffsetTop = ' + targetObjectOffsetTop);

    var tween = new TweenMax('.' + targetName, '3', {
      opacity: 0,
    });
    //mimic tween from behavior
     tween.pause();

    if (scrollAppearLocation > targetObjectOffsetTop) {
      //allow element to appear
      tween.reverse();
      tween.resume();
    } else {
      //hide element
      tween.restart();
      // tween.reverse();
      // tween.pause;
    }
  }

}

window.addEventListener('scroll', onScroll, false);
              
            
!
999px

Console