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

              
                <link href='//fonts.googleapis.com/css?family=Signika+Negative:300,400' rel='stylesheet' type='text/css'>
<h1>Press the buttons</h1>
<h3>requestedAnimation will not play until currentAnimation is done reversing</h3>
<div class="nav">
  <button id="play">green</button>
  <button id="restart">orange</button>
  <button id="restart">grey</button>
</div>
<div class="box green"></div>
<div class="box orange"></div>
<div class="box grey"></div>

              
            
!

CSS

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



              
            
!

JS

              
                var currentAnimation;
var requestedAnimation;



$("button").each(function(index, element){
    //give each button an animation
    //tell it to animate a box based on its text. green button animates element with class .green
    //each animation has an onReverseComplete that calls the playRequestedAnimation() function which checks if there is a requestedAnimation.
    var tl = new TimelineLite({paused:true, onReverseComplete:playRequestedAnimation})
    tl.to("." + $(this).text(), 4, {y:200, ease:Linear.easeNone})
    this.animation = tl;
 });



$("button").click(function(){
  //every time you click a button update the requestedAnimaiton variable
  requestedAnimation = this.animation;
  console.log("requested animation for", $(this).text())
  if(currentAnimation){
    //if there is a currentAnimation tell it to reverse
    console.log("currentAnimation needs to be reversed")
    currentAnimation.reverse();
  } else {
    playRequestedAnimation()
  }
  
  //if the requested animation is the currentAnimation, so imagine someone clicks a bunch of buttons like green, orange, green, you can skip over green reversing and orange playing forward entirely and just play green forward.
  if(requestedAnimation == currentAnimation){
    requestedAnimation.play();
  }
  
})

//when we are ready to play the requested animation tell it to play
//also update the currentAnimation to be the requestedAnimation
function playRequestedAnimation() {
  console.log("ready to play requested animation")
  requestedAnimation.play();
  currentAnimation = requestedAnimation;
}
              
            
!
999px

Console