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="one">1</div>
<div id="two">2</div>
<div id="three">3</div>
<div id="links">
  <div id="button1" class="butt">Animate one</div>
  <div id="button2" class="butt">Animate two</div>
  <div id="button3" class="butt">Animate three</div>
</div>
              
            
!

CSS

              
                body {
  font-family:"Source Sans Pro", sans-serif;
  background:#333;
  color:#fff;
}

#links {
  margin-top:20px;
}

.butt {
  padding:5px;
  width:150px;
  background-color:#33a;
  margin-bottom:5px;
}

.butt:hover {
  background-color:#00a;
}
              
            
!

JS

              
                var timelines = [], current = false;

timelines[0] = new TimelineMax({repeat:-1})
  .addPause ()
  .to("#one", 2, {x:500})
  .addPause ()
  .to("#one", 0.5, {x:0});

timelines[1] = new TimelineMax({repeat:-1})
  .addPause ()
  .to("#two", 2, {x:500})
  .addPause ()
  .to("#two", 0.5, {x:0});

timelines[2] = new TimelineMax({repeat:-1})
  .addPause ()
  .to("#three", 2, {x:500})
  .addPause ()
  .to("#three", 0.5, {x:0});

//loop through each butt (never thought I'd say that)
$(".butt").each(function(index, element){
  //assign each butt a timeline 
  element.timeline = timelines[index];
  //each butt will do the same things when clicked
  $(element).click(function(){
    //first if current isn't defined, this means this is the first butt clicked and we can tell its timleine to play with no further checks
    if (!current){
      current = this.timeline;
      current.play();
    //now we know there is a current timeline, if it is NOT active then we can set a new current and tell it to play
    } else if (current.isActive() === false){
      previous = current;
      current = this.timeline;
      
      previous.play();
      current.play(); // I want this to play after the previous one has finsihed.
    }
  });
});

/*
document.getElementById("button1").onclick = function() { 
  if ( current != 0 )
    timelines[current].play();
  alert (timelines[1].progress());
  if ( timelines[1].progress() === 0 ) {
    timelines[1].play(0);
    current = 1;
  }
}; 
*/

              
            
!
999px

Console