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

              
                <h1>Timeline is paused. Click 
"next with tweenTo" button and wait 3 seconds</h1>
<div id="demo">
  <div id="slideshow" class="slides">
    <div class="box red slide"></div>
    <div class="box blue slide"></div>
    <div class="box green slide"></div>
    <div class="box orange slide"></div>
  </div>
</div>
<div class="nav">
  <button id="next1">next with seek</button> 
  <button id="next2">next with tweenTo</button> 
</div>

              
            
!

CSS

              
                #demo {
  width:600px;
  height:120px;
  background-color:black;
}

#demo{
  position: relative;
  overflow: hidden;
}

.slides,
.slide{
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.box {
  width:600px;
  height:120px;
}

.red {
  background-color:red;
}

.blue {
  background-color:blue;
}

.green {
  background-color:green;
}

.orange {
  background-color:orange;
}

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

button {
  padding:10px;
  margin:10px;
}
              
            
!

JS

              
                var show = $('#slideshow');
var slides;
var prevWidth = 0;

show.append(show.find('.slide').first().prop('outerHTML'));
slides = show.find('.slide');

var timeline = new TimelineMax({
  repeat: -1, paused:true
});

slides.each(function(index){

  TweenMax.set(this, { 
    x:index * prevWidth
  });

  if(index > 0){
    
    timeline.add('slide_' + index);

    timeline.to(show, 1, {
      x: -index * prevWidth
    }, '+=3');
  }

  prevWidth = $(this).width();
});

$('#next1').on('click', function(){
  var nextLabel = timeline.getLabelAfter();
  
  if(nextLabel){
    timeline.seek(nextLabel);
  }else{
    timeline.play(0);
  }
});

$('#next2').on('click', function(){
  var nextLabel = timeline.getLabelAfter();
  
  if(nextLabel){
    timeline.tweenTo(nextLabel);
  }else{
    timeline.play(0);
  }
});
              
            
!
999px

Console