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 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

              
                <link href='//fonts.googleapis.com/css?family=Signika+Negative:300,400,600' rel='stylesheet' type='text/css'>
<div id="header"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/logo-man.svg" width="100" style="vertical-align: middle; margin-right: 16px;" /><h1>Advanced staggers by Key Positions</h1></div>
<div id="container"></div>
<div id="instructions">
  
</div>

              
            
!

CSS

              
                html, body {
  width: 0;         /* for fixing iOS iframe issues */
  min-width: 100%;  /* for fixing iOS iframe issues */
  overflow-x: hidden;
  position: relative;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
body {
  background-color: #222;
  text-align: center;
  color: #bbb;
  font-family: "Signika Negative", sans-serif;
  font-weight: 300;
  font-size: 18px;
  padding: 10px 0;
}
h1 {
  margin: 0;
  font-size: 50px;
  text-align: left;
}
h2 {
  font-size: 38px;
  margin-bottom: 0;
}
h1, h2, h3 {
  color: white;
  font-weight: 400;
}
h3 {
  margin-bottom: -12px;
}
#header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}
a {
  color: #88ce02;
  text-decoration: none;
  font-weight: 400;
}
a:hover {
  text-decoration: underline;
}
#container {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}
.box {
  background-color: #3b71a4;
  position: relative;
}
.box:before {
  padding-top:100%;
  content:"";
  display:block;
}
#instructions {
  margin-top: 35px;
  padding:0 16px 16px 16px;
  text-align: left;
  max-width: 1000px;
  display: inline-block;
}

.code {
  background-color: #111;
  padding: 12px;
  border-radius: 10px;
}
.featured {
  color: white;
}
strong {
  color: white;
  font-weight: 400;
  font-size: 20px;
}
.question {
  color: white;
  font-size: 21px;
  font-weight: 400;
  display: block;
}
#controls {
  text-align: center;
  display:flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.control {
  display: flex;
  align-items: flex-start;
  font-family: "Consolas", "Bitstream Vera Sans Mono", "Courier New", Courier, monospace;
  color: white;
  margin-bottom: 10px;
}
.control-label {
  margin-top: 10px;
}
.control-vertical {
  display: flex;
  flex-direction: column;
  align-content: flex-start;
  text-align: left;
  justify-content: flex-start;
  padding: 6px 8px;
  border-radius: 9px;
  background-color: #111;
  margin-right: 18px;
  color: #bbb;
}

.fr-video {
  display: block;
  position: relative;
  width: 100%;
  height: 0;
  float: left;
  padding-bottom: 56.25%;
  margin: 12px 0 35px 0;
}

.fr-video iframe {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  border: 2px solid #444;
}

#instructions li {
  margin-bottom: 10px;
}

@media only screen and (max-width: 640px) {
  h1 {
    font-size: 30px;
    line-height: 30px;
  }
  #controls {
    align-items: flex-start;
    justify-content: flex-start;
  }
}
              
            
!

JS

              
                //builds a grid of <div class="box"> elements, dropped into #container (unrelated to animation code)
buildGrid({grid:[15,9], className:"box", width:1000, gutter:15, parent:"#container"});

var tl = new TimelineMax({repeat:-1, repeatDelay:0.5});
tl.staggerTo(".box", 1, {
  scale:0.1, 
  y:60,
  yoyo:true, 
  repeat:1, 
  ease:Power1.easeInOut,
  stagger: {
    amount:1.5, 
    grid:"auto", 
    from:findPositionIndex(".box", "center", "top")
  }
});

//helper function that figures out the index number of the element that's at a key position like "center top", "right top", etc. Just feed in the array/NodeList/selector text of the elements, then the x position keyword, and then the y position keyword. 
function findPositionIndex(elements, x, y) {
  if (typeof(elements) === "string") {
    elements = document.querySelectorAll(elements);
  }
  var max = -Infinity,
      cols = 0,
      l = elements.length,
      factors = {center:0.5, bottom:1, right:1},
      rows;
	while (max < (max = elements[cols++].getBoundingClientRect().left) && cols < l) { }
	cols--;
  rows = (l / cols) | 0;
  return Math.floor((factors[y] || 0) * rows) * cols + (Math.floor((factors[x] || 0) * cols + 0.5) || 1) - 1;
}




//helper function to build a grid of <div> elements
function buildGrid(vars) {
	vars = vars || {};
	var container = document.createElement("div"),
		rows = vars.grid[1] || 5,
		cols = vars.grid[0] || 5,
		width = vars.width || 100,
		gutter = vars.gutter || 1,
    className = vars.className || "",
		w = (width - cols * gutter) / cols,
		parent = (typeof(vars.parent) === "string") ? document.querySelector(vars.parent) : vars.parent ? vars.parent : document.body,
		css = "display: inline-block; margin: 0 " + (gutter / width * 100) + "% " + (gutter / width * 100) + "% 0; width: " + (w / width * 100) + "%;",
		l = rows * cols,
		i, box;
	for (i = 0; i < l; i++) {
		box = document.createElement("div");
		box.style.cssText = css;
    box.setAttribute("class", className);
    box.index = i;
    box.setAttribute("data-index", i);
    if (vars.onCellClick) {
      box.addEventListener("click", vars.onCellClick);
    }
		container.appendChild(box);
	}
	container.style.cssText = "width:" + width + "px; line-height: 0; padding:" + gutter + "px 0 0 " + gutter + "px; display:inline-block;";
	parent.appendChild(container);
	return container;
}

//this just helps avoid the pixel-snapping that some browsers do.
TweenMax.set(".box", {rotation:0.5, force3D:true});
              
            
!
999px

Console