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

Auto Save

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

              
                <!-- animation container -->
<h2 class="animation-title">Frame by Frame Animation: #4 Transform (CSS + JavaScript for IE Fallback)</h2>
<div class="eye-animation__wrapper">
  <!-- sprite container(we will move this one) -->
  <div class="eye-animation"></div>
</div>
              
            
!

CSS

              
                .animation-title {
  font-family: sans-serif;
  text-align: center;
}

.eye-animation {
  // we move the HTML element inside its wrapper so we set the element's width accordingly
  width: 1800%;
  height: 100%;
  background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/123941/blinking-eye-sprite.svg');
  background-size: 100%, 100%;
  background-repeat: no-repeat;
  
  // 'animation-timing-function' ensures users won’t see half of one frame and half of the following frame both at the same time
  // we set the number of steps to 17 because we have 18 frames 
  animation-name: eye-fill;
  animation-duration: 1.3s;
  animation-timing-function: steps(17);
  animation-iteration-count: infinite;
  
  // we position the sprite so that left frame is visible
  position: absolute;
  left: 0;
  top: 0;
  
  // this is the wrapper around the HTML element being moved
  &__wrapper {
    // place it in the middle of the screen
    margin: auto;
    
    // show only one frame at a time, hide unnecesary parts of the moving HTML element
    overflow: hidden;
    // allow inner HTML element to be absolutely positioned
    position: relative;
    
    width: 300px;
    height: 300px;
  }
}

// move element from left to right
@keyframes eye-fill {
  from { 
    transform: translateX(0); 
  }
  to { 
    transform: translateX(-94.44444444%); 
  }
}

// fallback for IE
.ie {
  .eye-animation {
    // tell the browser to move the element into a separate compositing layer to improve performance
    transform: translate3d(0, 0, 0);
    
    animation-name: eye-fill-ie;
  }
}

// move element from left to right
@keyframes eye-fill-ie {
  from {
    left: 0;
  }
  to {
    left: -1700%;
  }
}
              
            
!

JS

              
                // we check if browser is Internet Explorer and if yes then we apply special class which we use in SCSS

var isIE = /Edge\/\d./i.test(navigator.userAgent) || /trident/i.test(navigator.userAgent);

if (_this.isIE) {
  $('html').addClass('ie');
}
              
            
!
999px

Console