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.

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

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.

Template

Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:

Screenshot

Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

HTML

              
                <div class='box'>

  <div class='animatedimage'>
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/1.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/2.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/3.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/4.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/5.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/6.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/7.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/8.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/9.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/10.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/11.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/12.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/13.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/14.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/15.png' width='128' height='128' />
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/29123/16.png' width='128' height='128' class='poster' />
    <!-- With this preloader, the 'empty' frame is the last frame, so we set image 16 to be the poster. animation will always start from the first image, which works well in this case -->
  </div>

  <p>Image sequence<br />16 pngs = 93.9KB</p>

</div>

<p>Click each box to pause/resume its animation</p>

              
            
!

CSS

              
                /* styles needed by the plugin */
.animatedimage {
  position: relative;
  display: inline-block;
  line-height: 0;
  overflow: hidden;
}
.animatedimage > * {
  position: absolute;
  display: inline-block;
  visibility: hidden;
  border: 0;
}
/* the image that will show while waiting for javascript to load, and what users without javascript will see - if you don't want to use a class you might use *:first-child to select this instead */
.animatedimage > .poster {
  position: static;
  visibility: visible;
}
/* spritesheets will rely on left/top positioning */
.animatedimage[data-spritesize] > * {
  position: relative;
}




/* demo styles */
body {
  padding: 10px;
  margin: 0;
  text-align: center;
  font: normal 12px sans-serif;
  background: #111;
  color: #FFF;
}
p {
  float: left;
  margin: 10px;
}
.box {
  float: left;
  width: 128px;
  margin: 10px;
  padding: 20px;
  background: #FFF;
  border-radius: 5px;
  color: #111;
  cursor: pointer;
}
.box p {
  float: none;
  margin: 20px 0 0 0;
}
.box:hover {
  box-shadow: 0 0 0 1px #FFF;
}
.animatedimage {
  pointer-events: none; /* the image sequence has a little trouble with click events when rapidly changing the images */
}
              
            
!

JS

              
                // make sure all the images have loaded before starting any animation
$(window).on('load', function() {

  // just adding a little delay at the start to extend the 'loading' to see what is shown before the plugin is activated
  TweenLite.delayedCall(2, function() {
    // activate animation on the animatedimage elements
    $('.animatedimage').animateimage(30, -1)
    // setup a click on the box to toggle the animation pause
    .parent().on('click', function() {
      var image = $(this).children('.animatedimage');
      
      // the plugin saves the animation in the 'animation' property of the DOM element e.g. image[0].animation
      if (image.prop('animation').paused()) {
        image.prop('animation').resume();
      } else {
        image.prop('animation').pause();
      }
    });
  });
});



;(function($) {
  $.fn.animateimage = function(framerate, repeats) {
    return this.each(function() {

      var $this = $(this);
        
      framerate = Math.abs(framerate || 10);
      if (typeof repeats === 'undefined' || repeats < -1) repeats = -1;
      var duration = 1 / framerate;
      var spritesize = $this.data('spritesize');
      
      // grab all children of the target element - these should just be the image/s to animate
      var image = $this.children();
      
        if (image.length > 1) { // image should only contain the images to be animated
          
          // these objects are used more than once but they only need to be created once
          var hidden = { position: 'absolute', visibility: 'hidden' };
          var visible = { position: 'static', visibility: 'visible' };
    
          // in case the poster is not the first child, make sure its pre-animated state is disabled
          image.filter('.poster').css(hidden);
    
          var lastimage = image.last();
          
          // attach a reference to the animation on the element, so it can be easily grabbed outside of the plugin and paused, reversed etc
          this.animation = new TimelineMax({ repeat: repeats })
              // this first set is not strictly needed as lastimage is underneath all of the other images, but it certainly doesn't hurt
              .set(lastimage, hidden)
              // toggle images one by one between visible and hidden - at any one time, only one image will be visible, and its static positioning will set the size for the container
              .staggerTo(image, 0, visible, duration, 0)
              // hide all the elements except lastimage - it will be hidden on repeat if needed at the same time as first is shown
              .staggerTo(image.not(lastimage), 0, $.extend(hidden, { immediateRender: false }), duration, duration)
              // add an 'empty' set after lastimage is made visible - this adds padding at the end of the timeline so lastimage is displayed for the correct duration before the repeat
              .set({}, {}, "+="+duration);
        }
        
      
    });
  };
}(jQuery));
              
            
!
999px
What did the colon say to the semicolon? Stop winking at me.

Console