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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <div class="header">
  <div id="move">Move</div>
</div>

<div id="content">
  <div id="row-0">Row 0</div>
  <div id="row-1">Row 1</div>
  <div id="row-2">Row 2</div>
  <div id="row-3">Row 3</div>
  <div id="row-4">Row 4</div>
  <div id="row-5">Row 5</div>
</div>


              
            
!

CSS

              
                .header {
  padding-bottom: 40px;
}

              
            
!

JS

              
                var numOfRows = 6;
init();

function init() {
  $("#move").click(function() {
    var $this = $(this);
    if (isMovingRows()) {
      $this.html("Drag");
      $this.removeClass("is-moving");
    } else {
      moveRowsStarted();
    }
  });
}

function isMovingRows() {
  if ($("#move").hasClass("is-moving")) return true;
  return false;
}

function moveRowsStarted() {
  $("#move").html("Stop Moving").addClass("is-moving");
  for (var i = 0; i < numOfRows; i++) {
    makeRowsDraggable($("#row-" + i));
  }
}

function moveRowsCompleted() {
  $("#move").html("Move Rows").removeClass("is-moving");
  for (var i = 0; i < numOfRows; i++) {
    var $row = $("#row-" + i);
    var draggable = Draggable.get($row);
    if (draggable) draggable.kill();
    $row.removeAttr("style");
  }
}

function makeRowsDraggable($row) {
  Draggable.create($row, {
    type: "y",
    cursor: "pointer",
    bounds: $("#content"),
    autoScroll: 1,
    onRelease: function() {
      var $dragRow = $(this.target);
      var id = $dragRow.attr("id");
      var rowIds = [];
      for (var i = 0; i < numOfRows; i++) {
        var $row = $("#row-" + i);
        if (this.hitTest($row) && $row.attr("id") !== id) {
          rowIds.push(i);
        }
      }

      if (rowIds.length == 1) {
        // positioned exactly on top of another row
        // if rowIds[0] == numOfRows then position below the last row and move others up
        // otherwise position at rowIds[0] location and move others down
        if (rowIds[0] == numOfRows - 1) $("#row-" + rowIds[0]).after($dragRow);
        else $("#row-" + rowIds[0]).before($dragRow);
      } else {
        // position between the two rows (rowIds[1] location and move others down)
        $("#row-" + rowIds[1]).before($dragRow);
      }
      
      	var draggable = Draggable.get($dragRow);
				draggable.kill();
				//$dragRow.removeAttr("style");
				moveRowsDraggable($dragRow);
    },
  });
}




              
            
!
999px

Console