Pen Settings



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


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


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.


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.


                <div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>
<div class="tile"></div>


                .tile {
  position: absolute;
  height: 100px;
  width: 200px;
  background: green;
  border: 1px solid black;



var tiles  = $(".tile");
var margin = 5;
var height = tiles.height();
var threshold = "25%";

Draggable.create(".tile", {
  onDragEnd: checkCollisions

// Start the inital tile layout

// Run a hit test on all the tiles
function checkCollisions() {
  var i = tiles.length;
  while (i--) {

    // Hit test the tiles and change their position if needed
    if (this.hitTest(tiles[i], threshold)) {
      changePosition($(, $(tiles[i]));
  // Move the tiles to their new position

// Change position between two elements
// This just changes the DOM structure, it doesn't actually move them visually
// This places the elements in the correct order so that they can be 
// Indexed correctly in the layoutTiles function
function changePosition(target1, target2) {

  // Compare indexes to determine if tile should be inserted before or after
  if ("index") >"index")) {
  } else {

function layoutTiles(initial) {
  $(".tile").each(function(i, node) {
    var time = 0.2;
    var y = i * margin + (i * height);
    // Initial setup
    if (initial) {
      time = 0;
    // (Re)-index each tile
    $(node).data("index", i);, time, { x: 0, y: y });