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

              
                <!-- Borrowed Grant from EaselJS https://www.createjs.com/Demos/EaselJS/SpriteSheet -->

<!-- Pefect, exactly what I wanted and was really easy to implement. -->
<div id="gsap" class="grant"></div>
<!-- Starts off okay, but lags terribly, probably need to re-write the jquery loop. -->
<div id="jquery" class="grant"></div>
<!-- Okay clearly step animation doesn't work that way! -->
<div id="css" class="grant"></div>
<div id="counter">1</div>
              
            
!

CSS

              
                @import "compass/css3";

* {
  box-sizing:border-box;
}

div {
  float:left;
  width: 165px;
  height: 292px;
}

.grant {
  background: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/59506/spritesheet_grant.png') 0px 0px;
}
#gsap{
  background-color: rgb(132,209,0);
}
#jquery{
  background-color: rgb(37,100,159);
}
#css{
  background-color: yellow;
  animation: animateGrant 100s steps(12, end) infinite;
}

#counter {
  font-size: 136px;
  padding: 66px;
  display: none;
}

$grantWidth: 165;
$grantHeight: 292;
$framesPerLine: 12;
$maxFrames:64;
$animationFPS: 12;
$percent: 0%;

@keyframes animateGrant {
  $animationRow: 1;
  $animationCol: 1;
  $animationXPos: 0px;
  $animationYPos: 0px;
  
  @for $i from 0 through 12 {
    $percent: (100% / $maxFrames) * (0 + $i);
    
    @if ($i >= ($framesPerLine * $animationRow)) {
      $animationRow: $animationRow + 1;
    }
    $animationYPos: 0 - ($grantHeight * ($animationRow - 1)) + px;
    
    @if ($animationCol <= $framesPerLine){
      $animationCol: $animationCol + 1;
    } @else {
      $animationCol: 0;
      $animationXPos: 0px;
    }
    $animationXPos: 0 - ($grantWidth * ($animationCol - 2)) + px;
    //This isn't working!
    #{$percent} {
      background-position-x: $animationXPos;
      background-position-y: $animationYPos;
    }
  }
}


              
            
!

JS

              
                var grant = {
  width: 165,
  height: 292,
  count: 0,
  maxCount: 64,
  line: 12
};
var animationFPS = 12;
var animationCol = 1;
var animationRow = 1;
var animationYPos = "0px";
var animationXPos = "0px";
var animPosition = [];
TweenMax.to(grant, (grant.maxCount / animationFPS), {
  count: grant.maxCount,
  currentCol: grant.line,
  ease: SteppedEase.config(grant.maxCount),
  repeat: -1,
  onUpdate: animateGrant
});
for (var i = 0; i < (grant.maxCount - 1); i++) {
  if (i >= (grant.line * animationRow)) {
    animationRow++;
  }
  animationYPos = "-" + (grant.height * (animationRow - 1)) + "px";

  if (animationCol < grant.line) {
    animationCol++;
    animationXPos = "-" + (grant.width * (animationCol - 1)) + "px";
  } else {
    animationCol = 1;
    animationXPos = "0 px";
  }

  animPosition[i] = animationXPos + " " + animationYPos;
}

function animateGrant() {
  //$('#counter').text(grant.count); 
  TweenMax.set('#gsap', {
    backgroundPosition: animPosition[grant.count]
  });
};

function loopGrant() {
  $({
    countNum: grant.count
  }).animate({
    countNum: (grant.maxCount - 1)
  }, {
    duration: (grant.maxCount / animationFPS) * 1000,
    easing: 'linear',
    step: function() {
      // What todo on every count
      var k = Math.floor(this.countNum);
      $('#jquery').css('background-position', animPosition[k]);
      //$('#counter').text(animPosition[k]); 
    },
    complete: function() {
      loopGrant();
    }
  });
}

loopGrant();
              
            
!
999px

Console