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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <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 = 0;

timelines[0] = new TimelineMax({paused:"true"})
  .addLabel("going")
  .to("#one", 2, {x:500})
  .addPause ()
  .addLabel("returning")
  .to("#one", 0.5, {x:0});

timelines[1] = new TimelineMax({paused:"true"})
  .addLabel("going")
  .to("#two", 2, {x:500})
  .addPause ()
  .addLabel("returning")
  .to("#two", 0.5, {x:0});

timelines[2] = new TimelineMax({paused:"true"})
  .addLabel("going")
  .to("#three", 2, {x:500})
  .addPause ()
  .addLabel("returning")
  .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){
      current = this.timeline;
      current.play();
    }
  })
})

              
            
!
999px

Console