cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <!--
A simple, extensible JavaScript-based timeline for use in CSS animation projects. Thsi example uses style changes on a simple circular element, but you can sequentially apply styles to CSS selectors in any order you want by using the JS animation array.
For more information, check out: http://mediatemple.net/blog/tips/building-an-animated-web-project-using-a-javascript-timeline/
-->

<div class="circle  step-1"> <!--start out with .step-1 applied to .circle-->
  <p>1</p>
  <p>2</p>
  <p>3</p>
  <p>4</p>
  <p>5</p>
</div>

<button id="run">
  Run animation
</button>

<button id="restart">
  Restart animation
</button>

<a href="http://mediatemple.net/blog/tips/building-an-animated-web-project-using-a-javascript-timeline/">Learn more at the Media Temple blog &rsaquo;</a>
            
          
!
            
              @color1: #e66705;
@color2: #ff9900;
@color3: #f47762;
@color4: #cccccc;
@color5: #8ebcc1;

// For this Pen, I'm animating the appearance of a circular element.
// With the animation array in the JS section below, you can sequentially
// apply styles to any CSS selector you choose.

.circle {
  width:300px;
  height:300px;
  border-radius:50%;
  position:absolute;
  top:50%;
  left:50%;
  margin:-150px 0 0 -150px;
  box-shadow:inset 0 0 3px rgba(0,0,0,.35);
  transition:background-color .15s linear;
  display:table; // so I can vertically align the child paragraph
  p {
    display:none;
    font-family:helvetica,arial,sans-serif;
    color:#ffffff;
    font-size:60px;
    font-weight:bold;
    text-shadow:0 1px 3px rgba(0,0,0,.5);
  }
}

// This is initial appearance of the element, step-1
.step-1 {
  background-color:@color1;
  p {
    &:nth-child(1){
      display:table-cell;
      vertical-align:middle;
      text-align:center;
    }
  }
}

// These are the styles to apply to the circle when .step-2 is added to .circle
// It's all about carefully overriding specfic styles in a certain order
.step-2 {
  background-color:@color2;
  p {
    &:nth-child(n){ // I need to overwrite all the other nth-child styles...
      display:none; // and make the previous number display:none
    }
    &:nth-child(2){
      display:table-cell;
      vertical-align:middle;
      text-align:center;
    }
  }
}

// Third step
.step-3 {
  background-color:@color3;
  p {
    &:nth-child(n){
      display:none;
    }
    &:nth-child(3){
      display:table-cell;
      vertical-align:middle;
      text-align:center;
    }
  }
}

// Fourth step
.step-4 {
  background-color:@color4;
  p {
    &:nth-child(n){
      display:none;
    }
    &:nth-child(4){
      display:table-cell;
      vertical-align:middle;
      text-align:center;
    }
  }
}

// Fifth step
.step-5 {
  background-color:@color5;
  p {
    &:nth-child(n){
      display:none;
    }
    &:nth-child(5){
      display:table-cell;
      vertical-align:middle;
      text-align:center;
    }
  }
}

// Peripheral styles
// These are just for the demonstration, they don't effect the animation at all

.interaction-text {
  font-family:helvetica,arial,sans-serif;
  font-size:18px;
  color:rgba(0,0,0,.8);
  font-weight:lighter;
}

button {
  background-color:transparent;
  border:2px solid #e8f5f7;
  padding:20px;
  border-radius:4px;
  cursor:pointer;
  cursor:hand;
  outline:none;
  .interaction-text;
  &:hover {
    background-color:#e8f5f7;
  }
  &:active {
    background-color:@color5;
    border-color:@color5;
  }
}

a {
  padding-left:20px;
  .interaction-text;
  text-decoration:none;
  &:hover {
    text-decoration:underline;
  }
}
            
          
!
            
              // This array sets up the animation steps
// time: number of milliseconds before adding the class
// step: the name of the class to add to the element
// selector: the name of the element that you're applying the class to

var animations = [
    {
        // Activate the second step, circle #2
        time:2000,
        step:"step-2",
        selector:'.circle'
    },
    {
        // Activate the third step
        time:2000,
        step:"step-3",
        selector:'.circle'
    },
    {
        // Activate the fourth step
        time:2000,
        step:"step-4",
        selector:'.circle'
    },
    {
        // Activate the fifth step
        time:2000,
        step:"step-5",
        selector:'.circle'
    }
];

// Grab data from the animation array
// and create sets of class additions to elements after defined setTimeouts

function runAnimation(i, timeline){
    setTimeout(function(){
        $(animations[i].selector).addClass(animations[i].step);
    }, timeline);
}

// Go through the array, and execute each step one at a time in order
// by doing runAnimation() on each array element

function animationTimeline(){
    var timeline = 0;

    for(var i=0; i<animations.length; i++){
        // for each step in the animation array
        // update timeline to be value of animations[i].time PLUS previous timeline value
        timeline = parseInt(animations[i].time, 10) + parseInt(timeline, 10);
        runAnimation(i, timeline);
    }
}

// Run the animation
$('#run').click(function(){
    animationTimeline();
});

// Restart the animation
$('#restart').click(function(){
    $('.circle').removeClass("step-2 step-3 step-4 step-5");
    animationTimeline();
});
                   
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console