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 class="controls">
  <button id="play">Play</button>
  <button id="record">Record</button>
</div>

<div class="box" id="stage" width="540" height="900" style="width: 540px; height: 900px;">
  <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="540" height="900" x="0" y="0" id="stage-master" style="background: rgba(0, 0, 0, 0);">
    <g id="text-box" class="svg-wrapper" ref="2" x="0" y="0" height="110" width="455" data-svg-origin="226.5 54">
      <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" role="img" width="455" height="110" viewBox="0 0 455 110" id="svg-2" class="svg inline" ref="2" x="0" y="0">
        <title>Move Me!</title>
        <g>
          <path fill="lavender" stroke="royalblue" stroke-width="4" d="M26.40 77.08L50.82 77.08L50.82 69.64L42.18 69.64L42.18 57.46L58.56 77.02L61.14 77.02L77.22 57.52L77.22 69.64L70.74 69.64L70.74 77.08L95.88 77.08L95.88 69.64L89.64 69.64L89.64 46.84L95.88 46.84L95.88 40.30L78.36 40.30L60.84 60.64L43.20 39.94L26.40 39.94L26.40 46.84L32.64 46.84L32.64 69.64L26.40 69.64Z"></path>
          <path fill="lavender" stroke="royalblue" stroke-width="4" d="M114.12 58.30C114.12 50.14 120.36 46.54 129.48 46.54C138.48 46.54 144.84 50.56 144.84 58.30C144.84 66.76 138.72 70.54 129.42 70.54C121.14 70.54 114.12 66.82 114.12 58.30ZM99.48 58.30C99.48 72.46 111.12 77.74 129.48 77.74C147.84 77.74 159.42 72.46 159.42 58.30C159.42 45.28 146.16 38.80 129.42 38.80C112.68 38.80 99.48 45.28 99.48 58.30Z"></path>
          <path fill="lavender" stroke="royalblue" stroke-width="4" d="M161.22 46.90L166.02 46.90L185.46 77.14L193.20 77.14L210.90 46.90L218.04 46.90L218.04 40L195.78 40L195.78 46.90L199.98 46.90L190.68 64.30L180.66 46.90L183.48 46.90L183.48 40L161.22 40Z"></path>
          <path fill="lavender" stroke="royalblue" stroke-width="4" d="M221.04 77.08L267.90 77.08L267.90 62.62L259.62 62.62L259.62 69.64L239.70 69.64L239.70 61.48L253.38 61.48L253.38 54.58L239.70 54.58L239.70 46.84L259.62 46.84L259.62 54.34L267.90 54.34L267.90 39.94L221.04 39.94L221.04 46.84L227.28 46.84L227.28 69.64L221.04 69.64Z"></path>
          <path fill="lavender" stroke="royalblue" stroke-width="4" d="M284.70 77.08L309.12 77.08L309.12 69.64L300.48 69.64L300.48 57.46L316.86 77.02L319.44 77.02L335.52 57.52L335.52 69.64L329.04 69.64L329.04 77.08L354.18 77.08L354.18 69.64L347.94 69.64L347.94 46.84L354.18 46.84L354.18 40.30L336.66 40.30L319.14 60.64L301.50 39.94L284.70 39.94L284.70 46.84L290.94 46.84L290.94 69.64L284.70 69.64Z"></path>
          <path fill="lavender" stroke="royalblue" stroke-width="4" d="M358.98 77.08L405.84 77.08L405.84 62.62L397.56 62.62L397.56 69.64L377.64 69.64L377.64 61.48L391.32 61.48L391.32 54.58L377.64 54.58L377.64 46.84L397.56 46.84L397.56 54.34L405.84 54.34L405.84 39.94L358.98 39.94L358.98 46.84L365.22 46.84L365.22 69.64L358.98 69.64Z"></path>
          <path fill="lavender" stroke="royalblue" stroke-width="4" d="M411.84 38.92L413.46 63.70L425.76 63.70L427.38 38.92ZM412.14 71.86C412.14 75.58 415.86 78.04 419.88 78.04C423.90 78.04 427.68 75.58 427.68 71.86C427.68 68.26 423.96 65.38 419.88 65.38C415.74 65.38 412.14 68.26 412.14 71.86Z"></path>
        </g>
      </svg>
    </g>
    <foreignOject height="900" width="540" x="0" y="40">
      <div style="position: absolute; top: 40px" xmlns="http://www.w3.org/1999/xhtml">
        <style>
          .animatedimage > * {
            position: absolute;
            display: 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;
          }
        </style>
        <div class='animatedimage'>
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left00.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left01.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left02.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left03.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left04.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left05.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left06.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left07.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left08.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left09.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left10.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left11.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left12.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left13.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left14.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left15.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left16.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left17.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left18.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left19.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left20.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left21.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left22.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left23.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left24.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left25.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left26.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left27.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left28.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left29.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left30.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left31.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left32.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left33.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left34.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left35.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left36.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left37.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left38.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left39.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left40.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left41.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left42.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left43.png" width="540" height="900" />
          <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left44.png" class="poster" width="540" height="900" />
        </div>
      </div>
    </foreignOject>
  </svg>
</div>

<div class="list"></div>
              
            
!

CSS

              
                /* styles needed by the plugin */

.text-box {
  position: relative;
}


/* demo styles */
body {
  padding: 10px;
  margin: 0;
  text-align: center;
  font: normal 12px sans-serif;
  background: #fff;
  color: #111;
}
.controls {
  text-align: left;
}
button {
  font-size: 16px;
  background: green;
  border: none;
  padding: 7px 20px;
  color: #fff;
  border-radius: 5px
}
p {
  float: left;
  margin: 10px;
}
.box {
  width: 540px;
  height: 900px;
  margin: 10px;
  padding: 20px;
  background: rgba(0,0,0,0);
  border-radius: 5px;
  cursor: pointer;
  overflow: hidden;
}
.box p {
  float: none;
  margin: 20px 0 0 0;
}
.box:hover {
  box-shadow: 0 0 0 1px #ccc;
}
.animatedimage {
  pointer-events: none; /* the image sequence has a little trouble with click events when rapidly changing the images */
}
              
            
!

JS

              
                var txtBox = $('#text-box');
TweenMax.set(txtBox,{opacity: 0, x: 10, y: 40});
var wordTl = new TimelineMax({paused: true});

wordTl.to(txtBox,0.3,{opacity: 1},0)
      .to(txtBox,0.3,{x: -80},0.5)
      .to(txtBox, 0.3,{x: -540},0.9);
// 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(5, function() {
    // activate animation on the animatedimage elements
    $('.animatedimage').animateimage(29.97, 0);
  });
  
  $('button#play').on("click", function(){
    $('.animatedimage').prop('animation').play(0);
  });
  
  $('button#record').on("click", function(){
    recordSequence($('.animatedimage').prop('animation'));
  });
});

function initImages() {
  for ( var i = 0; i <= 44; i++ ) {
    var filenum = i < 10 ? `0${i}` : i;
    var className = i == 44 ? " class='poster' " : " ";
    // $('.animatedimage').append(`<img${className}src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/81395/double_slide_left${filenum}.png" width="540" height="900" />`);
  }
}

initImages();

;(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 (spritesize) { // sprite sheet
        if (image.length === 1) { // image should be a single image containing the sprite sheet
          
          var horizontal = ($this.data('spritedirection') !== 'vertical');
          var spritecount = (horizontal ? image.width() : image.height()) / spritesize;
  
          TweenLite.set(image, { visibility: 'visible' });
          
          // 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 });
  
          if (horizontal) {
            TweenLite.set(this, { width: spritesize });
            for (var i = 0; i < spritecount; i++) {
              this.animation.set(image, { left: "-" + (i*spritesize) + "px" }, i*duration);
            }
          } else {
            TweenLite.set(this, { height: spritesize });
            for (var i = 0; i < spritecount; i++) {
              this.animation.set(image, { top: "-" + (i*spritesize) + "px" }, i*duration);
            }
          }
          // add an 'empty' set after the last position change - this adds padding at the end of the timeline so the last frame is displayed for the correct duration before the repeat
          this.animation.set({}, {}, i*duration);
        }

      } else { // image sequence
        if (image.length > 1) { // image should only contain the images to be animated
          
          // styles for hidden and visible image in the sequcnce
          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
          TweenLite.set(image.filter('.poster'), 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, repeatDelay: 1 })
              // 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)
              .addCallback(function(){ wordTl.seek(0).play()}, 0);
        }
        
      }
    });
  };
}(jQuery));

function recordSequence(animation) {
  
  var duration = animation.duration();
  var frames   = duration / 1 * 29.97;
  var current  = 0;

  processImage();

  function processImage() {

    animation.progress(current++ / frames);

    var xml  = new XMLSerializer().serializeToString($('#stage-master')[0]);
    var blob = new Blob([xml], { type: "image/png+xml" });
    var img  = new Image();

    img.crossOrigin = "Anonymous";  
    img.onload = function() {     
      list.appendChild(this);
    };

    img.src = URL.createObjectURL(blob); 

    if (current < frames) {
      processImage();
    } 
  }
}
              
            
!
999px

Console