Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                / setup transitions
- @transitions = ['bounceOut', 'fadeIn', 'fadeOut', 'callout.bounce', 'callout.shake', 'callout.flash', 'callout.pulse', 'callout.swing', 'callout.tada', 'transition.fadeIn', 'transition.fadeOut', 'transition.flipXIn', 'transition.flipXOut', 'transition.flipYIn', 'transition.flipYOut', 'transition.flipBounceXIn', 'transition.flipBounceXOut', 'transition.flipBounceYIn', 'transition.flipBounceYOut', 'transition.swoopIn', 'transition.swoopOut', 'transition.whirlIn', 'transition.whirlOut', 'transition.shrinkIn', 'transition.shrinkOut', 'transition.expandIn', 'transition.expandOut', 'transition.bounceIn', 'transition.bounceOut', 'transition.bounceUpIn', 'transition.bounceUpOut', 'transition.bounceDownIn', 'transition.bounceDownOut', 'transition.bounceLeftIn', 'transition.bounceLeftOut', 'transition.bounceRightIn', 'transition.bounceRightOut', 'transition.slideUpIn', 'transition.slideUpOut', 'transition.slideDownIn', 'transition.slideDownOut', 'transition.slideLeftIn', 'transition.slideLeftOut', 'transition.slideRightIn', 'transition.slideRightOut', 'transition.slideUpBigIn', 'transition.slideUpBigOut', 'transition.slideDownBigIn', 'transition.slideDownBigOut', 'transition.slideLeftBigIn', 'transition.slideLeftBigOut', 'transition.slideRightBigIn', 'transition.slideRightBigOut', 'transition.perspectiveUpIn', 'transition.perspectiveUpOut', 'transition.perspectiveDownIn', 'transition.perspectiveDownOut', 'transition.perspectiveLeftIn', 'transition.perspectiveLeftOut', 'transition.perspectiveRightIn', 'transition.perspectiveRightOut']

/ create some elements
#container
  %h2 Isotope / velocity performance test

#controls
  %div
    / %label Items:
    %input{:name => 'num_items', :type => "text", :value => 50}

    / %label Transition:
    %select{:name => 'transition'}
      - @transitions.each do |transition|
        %option{:value => "#{transition}"} 
          #{transition}

    %input{:type => 'checkbox', :name => 'toggle_transitions', :checked => 'checked'}
    %label toggle

    %input{:type => 'checkbox', :name => 'random_transitions'}
    %label randomize!

    %div#log log
              
            
!

CSS

              
                
.item {
  min-width: 80px;
  min-height: 80px;
  background: #222;
}

.item.width2 { width: 160px; }
.item.height2 { height: 160px; }

.item.width3 { width: 240px; }
.item.height3 { height: 240px; }


.clear {
  clear: both;
}

h2 {
  margin-top: 40px;
}


/*
 * some base style 
 */
body, html {
  margin: 0; padding: 0;
}
body {
  font-family: 'Helvetica Neue', Helvetica, arial, sans-serif;
  font-size: 118%;
  color: fff;
}

#controls {
  background: rgba(1, 1, 1, 0.3);
  position: fixed;
  top: 0px;
  left: 0px;
  width: 100%;
  padding: .4em;
}

#controls > div {
}

#controls p, #controls label {
  color: #fff;
  text-shadow: 1px 1px rgba(10, 10, 10, 0.2),
              -1px -1px rgba(10, 10, 10, 0.2);
}

#controls input {
  max-width: 50px;
  padding: 0; margin: 0;
}

#controls input, #controls select, #controls p {
  font-size: 82%;
}

/*#log {
  background: rgba(1, 1, 1, 0.8);
  font-size: 82%;
  padding: .2em;
  position: absolute;
  left: 0px;
  width: 100%;
}*/

#log {
  float: right;
  color: #fff;
  padding: 0 1em;
}
              
            
!

JS

              
                // testing out velocity + isotope
// isotope for layout (initial animation)
// velocity for the fancy animations (just scratching the surface here)

// code is a mess, will fix soon hopefully!

// external js:
// https://isotope.metafizzy.co/beta/isotope.pkgd.js


var $container = $('#container'),
    x = 1,
    int = 10;

var isoOptions = {
  itemSelector: '.item',
  masonry: {
    columnWidth: 40,
  }
};

var transitions = ['bounceOut', 'fadeIn', 'fadeOut', 'callout.bounce', 'callout.shake', 'callout.flash', 'callout.pulse', 'callout.swing', 'callout.tada', 'transition.fadeIn', 'transition.fadeOut', 'transition.flipXIn', 'transition.flipXOut', 'transition.flipYIn', 'transition.flipYOut', 'transition.flipBounceXIn', 'transition.flipBounceXOut', 'transition.flipBounceYIn', 'transition.flipBounceYOut', 'transition.swoopIn', 'transition.swoopOut', 'transition.whirlIn', 'transition.whirlOut', 'transition.shrinkIn', 'transition.shrinkOut', 'transition.expandIn', 'transition.expandOut', 'transition.bounceIn', 'transition.bounceOut', 'transition.bounceUpIn', 'transition.bounceUpOut', 'transition.bounceDownIn', 'transition.bounceDownOut', 'transition.bounceLeftIn', 'transition.bounceLeftOut', 'transition.bounceRightIn', 'transition.bounceRightOut', 'transition.slideUpIn', 'transition.slideUpOut', 'transition.slideDownIn', 'transition.slideDownOut', 'transition.slideLeftIn', 'transition.slideLeftOut', 'transition.slideRightIn', 'transition.slideRightOut', 'transition.slideUpBigIn', 'transition.slideUpBigOut', 'transition.slideDownBigIn', 'transition.slideDownBigOut', 'transition.slideLeftBigIn', 'transition.slideLeftBigOut', 'transition.slideRightBigIn', 'transition.slideRightBigOut', 'transition.perspectiveUpIn', 'transition.perspectiveUpOut', 'transition.perspectiveDownIn', 'transition.perspectiveDownOut', 'transition.perspectiveLeftIn', 'transition.perspectiveLeftOut', 'transition.perspectiveRightIn', 'transition.perspectiveRightOut'];

var transitions_in, transitions_out;

function get_random_transition()
{
   return transitions[Math.floor(Math.random() * transitions.length)];
}

// set some defaults
$('select').val(get_random_transition());

// append a random item
function appendItem() {
    // create element
    var $elems = getItemElement();

    // append elements to container
    $container.append( $elems )
      // add and lay out newly appended elements
      .isotope( 'appended', $elems );

}

function log(content)
{
  $('#log').html(content);  
}

// nifty randomize array function
function shuffle(o) {
    for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
    return o;
};

// make <div class="item width# height#" />
function getItemElement() {
  ++x;
  
  var random_hex = '#'+Math.floor(Math.random()*16777215).toString(16); // random hex color using magic 
  var $item = $('<div class="item" id="item-' + x + '" style="background: ' + random_hex + ';">'
                // + '<img src="http://adrapid.com/img/spinners/svg/loading-spin.svg">'
                + '</div>');
  
  // add width and height class
  var wRand = Math.random();
  var hRand = Math.random();
  var widthClass = wRand > 0.85 ? 'width3' : wRand > 0.7 ? 'width2' : '';
  var heightClass = hRand > 0.85 ? 'height3' : hRand > 0.5 ? 'height2' : '';
  $item.addClass( widthClass ).addClass( heightClass );
  return $item;
}

function doTest() {
   
  var timer = 0,
      duration = 1000,
      stagger = 30,
      delay = 250,
      toggle = $('input[name=toggle_transitions]').prop('checked'), 
      random_transitions = $('input[name=random_transitions]').prop('checked'),
      drag = false;

  // randomize transition
  if(toggle) $('select').val(get_random_transition());
    
  var transition = $('select').val(),
      max = $('input[name=num_items]').val(),
      m = 1; // temp vars

  // reset count
  x = 0;
  
  // flush container, destroy isotope 
  log('Destroying elements');
  $container.html(' '); // $('.item').detach();   
  $container.isotope('destroy');  

  // re-initialize
  $container.isotope( isoOptions );

  // create elements
  log('Creating elements, animating using isotope');
  for (i = 0; i < max; i++) { 
    setTimeout(function() {
      appendItem(); 
    }, 0) // delay * i
  }

  // do velocity animations
  setTimeout(function() {

    // do some crazy randomization
    if(random_transitions) {

      // create & pop array of order elements
      var elems = []; for(i = 0; i < max; ++i) elems[i] = i;
      
      // randomize order(?)
      shuffle(elems);

      // randomize animation duration ? 
      // randomize animation delay ? 

      for(n = 0; n < max; ++n) {
        single_animation(elems[n], get_random_transition(), duration, n*stagger);
      }
    } else {
      // hide elements if we are using an entry transition
      if (transition.indexOf('In') >= 0)
      {
        log('Hiding elements');
        $('.item').hide();
      }

      // need a sligt timeout to allow hide event to complete (?)
      setTimeout(function() {
         log('Animating using velocity: ' + transition);
         $('.item').velocity(transition, { 'duration': duration, 'stagger': stagger});  
      }, 100);
    }
  }, 1400);
}

// handle animation
function random_elems(elems, args) {
  
}

// handle animation of single element
function single_animation(id, transition, duration, delay) {
  setTimeout(function() {
    log('animating item#' + id + ' : ' + transition);
    $('#item-' + id).velocity(transition, { 'duration': duration});    
  }, delay); 
} 

$('#append').on( 'click', function() {
  doTest();  
});

// setup animation loop
function anim()
{
  doTest();
  
  setTimeout(function() {
    anim();
  }, 5000);
}

// initialize
anim();
              
            
!
999px

Console