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

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="changeable"></div>
<p id="support-message">Full demo only in browsers that support <span id="waapi-support">Web Animations API</span> and <span id="set-support">Animation.effect.setKeyframes()</span></p>
              
            
!

CSS

              
                body {
  overflow: hidden;
  height: 100vh;
  display: flex;
  justify-content: center;
  background: #db7b48;
}
#changeable {
  border: .2rem solid rgba(255,255,255,.8);
  background: #4589b4;
  width: 10vmin;
  height: 10vmin;
  border-radius: 50%;
  margin-top: 1vmin;
}
button {
  position: absolute;
  bottom: 1rem;
  width: 30vw;
  left: 35vw;
  appearance: none;
  border-radius: 1rem;
  padding: .5rem;
  border: .2rem solid transparent;
  min-height: 3rem;
  font-size: 1rem;
  background: #efefff;
  
  &:active {
    transform: translate3d(0,.2rem,0);
  }
  &:focus {
    border-color: rgba(50,150,100,.8);
    outline:0;
  }
  
  &::after {
    content: '\2194';
    display: block;
  }
  .vertical &::after {
    content: '\2195'
  }
}
p {
  font-family: -apple-system, "Segoe UI", "Helvetica Neue", sans-serif;
  line-height: 1.33;
  position: absolute;
  bottom: 0;
  padding: 1rem;
  left: 0;
  right: 0;
  text-align: center;
  background-color: #efefff;
  
  .supported & {
    display: none;
  }
  
  span {
    font-weight: 600;
    color: #ab4845;
    
    &.supported {
      color: #45ab78;
    }
  }
}
              
            
!

JS

              
                var changer = document.getElementById('changeable');
var options = {
  frames: [
    [
      {transform: 'translate3d(-40vmin,0,0)' },
      {transform: 'translate3d(40vmin,0,0)'}
    ],
    [
      {transform: 'translate3d(0,0,0)'},
      {transform: 'translate3d(-20vmin,30vmin,0)'},
      {transform: 'translate3d(20vmin,60vmin,0)'},
      {transform: 'translate3d(0,80vmin,0)'}
    ]
  ],
  timing: {
    duration: 3000,
    iterations: Infinity,
    easing: 'ease-in-out',
    direction: 'alternate'
  }
}

var animation;
if (typeof changer.animate === 'function') {
  console.log('using Element.animate();');
  document.getElementById('waapi-support').classList.add('supported');
  var animation = changer.animate(
    options.frames[0], 
    options.timing
  );
} else if (window.KeyframeEffect && window.Animation) {
  console.log('using KeyframeEffect + Animation constructors');
  document.getElementById('waapi-support').classList.add('supported');
  var kfe = new KeyframeEffect(
    changer,
    options.frames[0],
    options.timing
  );
  var animation = new Animation(kfe, document.timeline);
  animation.play();
}


//mix up the keyframes if setKeyframes is possible
if (animation && typeof animation.effect === 'object') {
  
  //Used to be called .setFrames(), so earlier editions of Firefox Nightly might use that
  if (typeof animation.effect.setKeyframes !== 'function' && typeof animation.effect.setFrames === 'function') {
    animation.effect.setKeyframes = animation.effect.setFrames
  }
  
  //if setKeyframes is supported, remove the support messaging, and add a button to toggle between to keyframe objects
  if (animation.effect.setKeyframes) {
    document.documentElement.classList.add('supported');
    var button = document.createElement('button');
    button.textContent = 'Change Keyframes';
    document.body.appendChild(button);
    var current;
    button.addEventListener('click', function() { 
      current = current ? 0 : 1;
      console.log(current);
      document.documentElement.classList[current ? 'add' : 'remove']('vertical')
      
      //this is the line that really does the magic
      animation.effect.setKeyframes(options.frames[current]);
    });
  }
}

              
            
!
999px

Console