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

Auto Save

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

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                
var svgns = "http://www.w3.org/2000/svg";
var createSvg = document.createElementNS.bind(document, svgns);

var cells = [];

var rows = 4;
var cols = 5;

var gutter = 3;
var cellWidth  = 50;
var cellHeight = 50;
var gridWidth  = cols * cellWidth  + (cols - 1) * gutter;
var gridHeight = rows * cellHeight + (rows - 1) * gutter;

var evenFill = "#3f51b5";
var oddFill  = "#607d8b";

var svg = appendTo(createSvg("svg"), document.body);

TweenLite.set(svg, {
  background: "#1a1a1a",
  position: "absolute",
  width: "100%",
  height: "100%",
  attr: {
    viewBox: "0 0 " + gridWidth + " " + gridHeight,
    preserveAspectRatio: "xMidYMid meet",
  }
});

for (var row = 0; row < rows; row++) {
  for (var col = 0; col < cols; col++) {
    
    var element = appendTo(createSvg("rect"), svg);
    cells.push(element);
    
    TweenLite.set(element, {
      x: col * cellWidth  + col * gutter,  
      y: row * cellHeight + row * gutter,  
      width:  cellWidth,
      height: cellHeight,
      fill: (row * cols + col) % 2 ? oddFill : evenFill,
    });    
  }
}

TweenLite.set(cells, { transformOrigin: "center center" });

var timeline = new TimelineMax({ 
  repeat: -1, 
  repeatDelay: 0.5, 
  yoyo: true 
});

timeline
  .add(cells.filter(isEven).reduce(fadeIn, new TimelineMax()))
  .add(cells.filter(isOdd).reduce(fadeOut, new TimelineMax()), "+=0.5")

function fadeIn(tl, cell) {
  return tl.fromTo(cell, 0.75, { scale: 0.5, autoAlpha: 0 }, { scale: 1, autoAlpha: 1 }, 0);
}

function fadeOut(tl, cell) {
  return tl.fromTo(cell, 0.75, { scale: 1, autoAlpha: 1 }, { scale: 0.5, autoAlpha: 0 }, 0);
}

function isEven(cell, i) {
  return !(i % 2);
}

function isOdd(cell, i) {
  return !!(i % 2);
}

function appendTo(child, parent) {
  parent.appendChild(child);
  return child;
}

              
            
!
999px

Console