cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <ul id="drop">
  <li draggable="true" contenteditable="true">List Item 1</li>
  <li draggable="true" contenteditable="true">List Item 2</li>
  <li draggable="true" contenteditable="true">List Item 3</li>
  <li draggable="true" contenteditable="true">List Item 4</li>
  <li draggable="true" contenteditable="true">List Item 5</li>
  <li draggable="true" contenteditable="true">List Item 6</li>
</ul>
            
          
!
            
              @import "compass/css3";

// Sortable / Editable List
// ---------------------------------------------------

// Imports
// ----------------------------------------------------
@import url(http://weloveiconfonts.com/api/?family=entypo);

// Variables
// ----------------------------------------------------
$list-width:               60% !default;
$list-style:               none !default;
$list-item-display:        block !default;  
$list-font-size:           18px !default;
$list-font:                $list-font-size Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans", "Gill Sans MT", "Myriad Pro", Myriad, "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif !default;
$list-background:          #62B158 !default;
$list-color:               white !default;
$list-padding:             12px !default;
$list-cursor:              move !default;
$list-focus-background:    orange !default;
$list-focus-cursor:        text !default;
$list-drop-target-height:  #{$list-font-size + $list-padding + $list-padding} !default;
$default-animation-name: placeholder !default;
$default-animation-duration:1.25s !default;
$default-animation-delay: 0s !default;
$default-animation-iteration-count:  infinite !default;
$default-animation-timing-function: ease-in-out !default;

// Mixins
// ----------------------------------------------------
@mixin pulse {
  0%   { background: lighten($list-background, 25%); }
  100% { background: lighten($list-background, 15%); }
}

@mixin animation-name($animation-name: $default-animation-name) {
  -webkit-animation-name: $animation-name;
  -moz-animation-name: $animation-name;
  -ms-animation-name: $animation-name;
  -o-animation-name: $animation-name;
  animation-name: $animation-name;
}
  
@mixin animation-duration($animation-duration: $default-animation-duration) {
  -webkit-animation-duration: $animation-duration;
  -moz-animation-duration: $animation-duration;
  -ms-animation-duration:  $animation-duration;
  -o-animation-duration:  $animation-duration;
  animation-duration:  $animation-duration;
}
    
@mixin animation-delay ($animation-delay: $default-animation-delay) {
  -webkit-animation-delay: $animation-delay;
  -moz-animation-delay: $animation-delay;
  -ms-animation-delay: $animation-delay;
  -o-animation-delay: $animation-delay;
  animation-delay: $animation-delay;
}
  
@mixin animation-iteration-count ($iteration-count: $default-animation-iteration-count) {
  -webkit-animation-iteration-count: $iteration-count;
  -moz-animation-iteration-count: $iteration-count;
  -ms-animation-iteration-count: $iteration-count;
  -o-animation-iteration-count: $iteration-count;
  animation-iteration-count: $iteration-count;
}
  
@mixin animation-timing-function ($timing: $default-animation-timing) {
  -webkit-animation-timing-function: $timing;
  -moz-animation-timing-function: $timing;
  -ms-animation-timing-function: $timing;
  -o-animation-timing-function: $timing;
  animation-timing-function: $timing;
}
  
@keyframes placeholder {
  @include pulse;
}

@-webkit-keyframes placeholder {
  @include pulse;
}

@-moz-keyframes placeholder {
  @include pulse;
}
          
@-o-keyframes placeholder {
  @include pulse;
}

body {
  background: #EEEFF1;
  padding: 0;
  margin: 0;
}

[draggable] {
  -moz-user-select: none;
  -khtml-user-select: none;
  -webkit-user-select: none;
  user-select: none;
  -khtml-user-drag: element;
  -webkit-user-drag: element;
}

// Drop Zone
ul {
  padding: 0;
  margin: 0 auto;
  width: $list-width;
  list-style: $list-style; 
  
  // List item
  > li {
    @include box-sizing(border-box);
    display: $list-item-display;
    padding: $list-padding;
    font: $list-font;
    background: $list-background;
    border-top: 1px solid lighten($list-background, 5%);
    border-bottom: 1px solid darken($list-background, 5%);
    color: $list-color;
    cursor: $list-cursor;
    outline: none;
    
    &:focus {
      @include transition(background 0.1s ease-in);
      background: lighten($list-background, 5%);
      cursor: $list-focus-cursor;
      
      // Icon - Entpyo - Edit
      &:before {
        @include transition(background 0.2s ease-in);
        display: block;
        float: left;
        content: '\270E';
        color: $list-color;
        margin-right: 8px;
      }
    }

    &:first-child {
      background: none;
      border: 0;
    }  
  }
}

  // Drop target  
.placeholder {
  @include animation-name($default-animation-name);
  @include animation-iteration-count($default-animation-iteration-count);
  @include animation-delay($default-animation-delay);
  @include animation-duration($default-animation-duration);
  @include animation-timing-function($default-animation-timing-function);
  display: none;
  margin: $list-padding -#{$list-padding} -#{$list-padding} -#{$list-padding};
  height: $list-drop-target-height;
  border-top: 1px solid darken($list-background, 5%);
}

ul > li:first-child .placeholder {
  animation: none;
  -webkit-animation: none;
  background: transparent !important;
  display: block;
  border: 0;
}
            
          
!
            
              // Sortable / Editable List
// ---------------------------------------------------
// Uses vanilla Javascript and the HTML5 drag and drop
// functionality (+ Modernizr to detect support)

if (Modernizr.draganddrop) {

var dragItems = document.querySelectorAll('[draggable=true]'),
	dragItemsLen = dragItems.length,
	dropZone = document.querySelector('#drop');

function init () {
  // Add placeholder for each list item
  for (var i = 0; i < dragItemsLen; i++) {
    addPlaceholder(dragItems[i]);
  }

  // Add extra placeholder for before first list item
  var firstLi = document.createElement('li');
  dropZone.insertBefore(firstLi, dropZone.firstChild);
  addPlaceholder(firstLi);

  watchDragEvents();

  return;
}

function addPlaceholder (target) {
  var placeholder = document.createElement('div');

  placeholder.setAttribute('class', 'placeholder');

  return target.appendChild(placeholder);
}

function togglePlaceholder (target, toggle) {
  if (target.getElementsByClassName('placeholder').length > 0) {
    return target.getElementsByClassName('placeholder')[0].style.display = (toggle === 'show') ? 'block' : 'none';
  }
}

function cancel (e) {
  e.preventDefault();

  return false;
}

function insertAfter (referenceNode, newNode) {
  return referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}

function watchDragEvents () {
  var dragged,
      currentItem,
      placeholders = document.getElementsByClassName('placeholder'),
  	  placeholdersLen = placeholders.length;

  for (var i = 0; i < dragItemsLen; i++) {

    // Enable / disable draggable and contenteditable on click / blur so they play nice together    
    dragItems[i].onclick = function () {
      this.setAttribute('data-draggableDisabled', 1);
      this.removeAttribute('draggable');
    }
    
    dragItems[i].onblur = function () {
      this.setAttribute('draggable','true');
      this.removeAttribute('data-draggableDisabled');
    }
  
  	addEvent(dragItems[i], 'dragenter', function (e) {
      // e.target = Webkit / IE
      // e.currentTarget = Mozilla
      if (e && (e.target || e.currentTarget)) {
      	// Show the list item's placeholder / drop target
        if (e.target) {
      	  togglePlaceholder(e.target, 'show');
        } else {
          togglePlaceholder(e.currentTarget, 'show');
        }
        // If first list item, show the preceding placeholder / drop target too
        // eg. enable drag to top of list
        for (var j = 0; j < dragItemsLen; j++) {
          if (dragItems[j] == e.srcElement || dragItems[j] == e.currentTarget) {
          	currentItem = j;

            if (j === 0) {
          	  togglePlaceholder(dropZone, 'show');
            }

            return;
          }
        }
      }
  	});

  	addEvent(dragItems[i], 'dragleave', function (e) {
  	  // Hide all but the current placeholder / drop target
  	  togglePlaceholder(e.target, 'hide');
      console.log(currentItem);
  	  togglePlaceholder(dragItems[currentItem], 'show');
  	});

    addEvent(dragItems[i], 'dragstart', function (e) {
      dragged = this;
      e.dataTransfer.setData('Text', this);
      this.style.opacity = '0.9';
    });
    
    addEvent(dragItems[i], 'dragend', function (e) {
      if (dragged) {
        dragged.style.opacity = '1';
      }
  	  togglePlaceholder(e.target, 'hide');
    });
  
  }

  for (var k = 0; k < placeholdersLen; k++) {
    
    addEvent(placeholders[k], 'dragover', cancel);

	  addEvent(placeholders[k], 'dragenter', cancel);
    
	  addEvent(placeholders[k], 'drop', function (e) {
	    e.preventDefault();

	    // Move the drag item into place
	    insertAfter(this.parentNode, dragged);

      // Reset the current drag item and placeholders / drop target
      dragged.style.opacity = '1';
	    dragged = null;
      for (var l = 1; l < placeholdersLen; l++) {
        placeholders[l].style.display = 'none';
      } 

	    return false;
	  }); 
  }  

  return;
}

init();

}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console