<h1>Demo 3: JavaScript-Powered Timing Functions</h1>

<p>A responsive sprite animation with a duration of 2 seconds, triggered when the user scrolls past a particular position. Scroll down to start playback, and back up to reverse the animation. Try altering the font-size to scale the sprite up and down.</p>

<div class="container">
  <div class="cnc" id="js-animation"></div>

<p class="p">Demo by Tom Bennet. <a href="http://www.sitepoint.com/responsive-sprite-animations-imagemagick-greensock" target="_blank">See article</a>.</p>
body {
  padding: 20px;
  text-align: center;

.container {
  font-size: 15em;
  min-height: 105vh;

.cnc {
  width: 1em;
  margin: auto;
  height: 1em;
  background:  url('http://bennet.org/images/codepen/cnc-sprite-demo.png') no-repeat 0 0%;
  background-size: 100%;

h1 {
  font-size: 1.2em;

p {
  width: 60%;
  margin: auto;
  text-align: left;

.p {
  margin-top: 120px;
  font-size: 14px;
  text-align: center;
// initialise ScrollMagic controller
var controller = new ScrollMagic.Controller();

// create Tween
var tween = TweenMax.to("#js-animation", 2.0, {
	backgroundPosition: "0 100%", 
	ease: SteppedEase.config(31)

// build scene
var scene = new ScrollMagic.Scene({triggerElement: "#js-animation"})

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/gsap/1.16.1/TweenMax.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.2/ScrollMagic.min.js
  3. https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/2.0.2/plugins/animation.gsap.min.js