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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <button class="btn0">panel 0</button>
<div class="panel panel0">
  <div class="inner">
    <h1>panel 0 header</h1>
    <h2>panel 0 sub-head</h2>
    <p>panel 0 content</p>
  </div>
</div>
<button class="btn1">panel 1</button>
<div class="panel panel1">
  <div class="inner">
    <h1>panel 1 header</h1>
    <h2>panel 1 sub-head</h2>
    <p>panel 1 content</p>
  </div>
</div>
              
            
!

CSS

              
                /* Global styles come from external css https://codepen.io/GreenSock/pen/JGaKdQ*/

h1 {
  font-size:32px;
}

p{
  color:#333;
}
.panel {
  width:300px;
  height:300px;
  background:grey;
  overflow:hidden;
  position:relatvive;
}

.inner{
  
  padding:20px;
}




              
            
!

JS

              
                $("button").each(function(index, element){
  
  
  //this introduces child elements in sequence
  var introAnimation = new TimelineLite({paused:true})
  introAnimation.from(".panel" + index + " h1", 0.3, {x:500, opacity:0})
    .from(".panel" +index + " h2", 0.3, {x:500, opacity:0})
    .from(".panel" +index + " p", 0.3, {x:500, opacity:0});
  
  
  //this animation opens or closes the panel
  element.openAnimation = TweenMax.from(".panel" + index, 1,{height:0, paused:true, onReverseComplete:resetIntro, onReverseCompleteScope:this});
  
  element.introAnimation = introAnimation;
  element.open = false; //panels closed by default
  element.index = index;
  
  //this gets triggered by openAnimation's onReverseCompleteCallback so that things get reset when panel closes
  function resetIntro() {
    this.introAnimation.pause(0);
  }
  
  
  function playIntro() {
    //if the introAnimation is partially revealed then keep playing it forward
    // this condition is necessary if people click open / close very quickly.
    if(this.introAnimation.progress() > 0){
      this.introAnimaiton.play()
    } else {
      this.introAnimation.restart();  
    }
  }
  
  //figure out what to do on each click based on whether or not panel is open or closed
  
  $(this).click(function(){
    
    // if panel isn't open then play the openAnimaiton and 0.5 seoconds later play the introAnimation
    if(!this.open){
      this.openAnimation.play();
      //0.5 seconds after telling the open animation to play, call a function that will play the introAnimation
      TweenLite.delayedCall(0.5, playIntro, null, this);
      this.open = true;
    } else {
      //panel is open, lets close it
      this.openAnimation.reverse()
      this.open = false;
    }
  });
});


              
            
!
999px

Console