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

              
                .controls
  %button#prepend PREPEND CHANNEL
  %button#append APPEND CHANNEL
  %button#reset RESET CHANNELS
.channels
  .channel#c1
    #block
              
            
!

CSS

              
                .controls
  width: 720px
  margin: 5px auto 0
  button
    position: relative
    display: inline-block
    background: green
    border: none
    color: white
    font-size: 16px
    margin: 0 20px 0 0
    cursor: pointer
    &#reset
      float: right
      margin-right: 0
.channels
  position: relative
  width: 720px
  margin: 5px auto
  background: black
.channel
  position: relative
  height: 50px
  width: 720px
  background: #b2b2b2
  margin: 0 0 2px
  &.selected
    background: #dddddd
  #block
    top: 0
    left: 0
    position: relative
    display: block
    height: 50px
    width: 100px
    background: green
    vertical-align: middle
              
            
!

JS

              
                let block = document.getElementById('block'),
    chContainer = document.querySelector('.channels'),
    allChannels = Array.from(document.querySelectorAll('.channel')),
    parentChannel = block.parentNode,
    draggable;

function setDrag() {
  if (draggable) {
    draggable.kill();
  }
  draggable = Draggable.create(block,{
    type:"top,left",
    bounds: '.channels',
    lockAxis: true,
    dragClickables: false,
    snap: {
      left: function(endVal) {
        return Math.round(endVal);
      }
    },
    onDrag: function(e) {
      for( let ch of allChannels ) {
        if (this.hitTest(ch, "50%")) {
          $('.channel').removeClass('selected');
          ch.classList.add('selected');
        }
      }
    },
    onRelease: function() {
      for( let ch of allChannels ) {
        if (this.hitTest(ch, "50%")) {
          $('.channel').removeClass('selected');
          ch.appendChild(block);
          TweenMax.set(this.target,{top: 0});
        }
      }
    }
  })[0];
}

function setResizable() {
  $(block).resizable({
    containment: 'parent',
    handles: 'e,w',
    create: function() {
      $('.ui-resizable-handle').attr('data-clickable',true);
      $('.ui-resizable-handle').on('mousedown', function(){
        draggable[0].disable();
      });
    },
    stop: function() {
      draggable[0].enable();
    }
  })
}

setResizable();
setDrag();

function addChannel(dir) {
  let ch = document.createElement('div');
  ch.id = `c${allChannels.length+1}`;
  ch.className = 'channel added';
  if( dir == 'prepend' ) {
    chContainer.insertBefore(ch,allChannels[0]);  
  } else {
   chContainer.appendChild(ch);
  }
  allChannels = Array.from(document.querySelectorAll('.channel'));
}

function resetChannels() {
  $('.channel.added').remove();
  allChannels = Array.from(document.querySelectorAll('.channel'));
  if( $('#block').length == 0 ) {
    block = document.createElement('div');
    block.id = 'block';
    allChannels[0].appendChild(block);
  }
  parentChannel = block.parentNode;
  setDrag();
}

$('.controls button').on('click', function(){
  if( this.id == 'reset' ) {
    resetChannels();
  } else {
    addChannel(this.id); 
  }
});
              
            
!
999px

Console