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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <div id="app">
  <div v-dragdrop="chapters" order="order">
    <div v-for="chapter in chapters" :key="chapter.id">
      {{ chapter.title }} 
      <strong>(order: {{ chapter.order }})</strong>
              * {
  margin: 0;
  padding: 0;

html, body, #app {
  font-family: system, helvetica;

#app {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #F4FAFA;
  background: url('https://res.cloudinary.com/lorisleiva/image/upload/v1519826829/backgrounds/1.jpg') center;
  background-size: cover;

#app > div {
  padding: 1em;
  border-radius: 1em;
  background-color: white;
  cursor: move;
  box-shadow: 2px 2px 5px rgba(0,0,0,0.05)

#app > div > div {
  padding: .5em 1em;
  border-radius: .5em;

#app > div > div:hover {
  background-color: #455;
  color: white;
 * Dragdrop directive.

let arrays = [];
let drakes = [];

Vue.directive('dragdrop', {
    bind (container, binding, vnode) {
        let orderProperty = vnode.data.attrs ? vnode.data.attrs.order : undefined;
        let items = binding.value || [];
        let dragIndex;

        let drake = dragula([container])
            .on('drag', (el, source) => {
                dragIndex = findDomIndex(source, el);
            .on('drop', (el, target) => {
                move(items, dragIndex, findDomIndex(target, el));
                if (orderProperty) reorder(items, orderProperty);
        addDrake(items, drake);

    unbind (container, binding, vnode) {

 * Find the index of an DOM element within a given container.
function findDomIndex(container, el) {
    return Array.prototype.indexOf.call(container.children, el);

 * Move an array item from one index to another.
 * The given array is transformed, not returned.
function move(array, fromIndex, toIndex) {
    array.splice(toIndex, 0, array.splice(fromIndex, 1)[0]);

 * Reorder the items of an array from 0 to `array.length`.
 * The new order is stored on the given `orderProperty`.
 * The given array is transformed, not returned.
function reorder(array, orderProperty) {
    let newOrder = 0;
    array.forEach(item => { _.set(item, orderProperty, newOrder++) })

 * Register a drake instance based on the reference of the given array.
function addDrake(array, drake) {
    if (arrays.indexOf(array) >= 0) return;

 * Retrieve a drake instance based on the reference of the given array.
function getDrake(array) {
    let drakeIndex = arrays.indexOf(array);
    if (drakeIndex >= 0) return drakes[drakeIndex];

 * Start the VueJS application.
new Vue({
  el: '#app',
  data: {
    chapters: [
      { id: 1, title: 'The Boy Who Lived', order: 0 }, 
      { id: 2, title: 'The Vanishing Glass', order: 1 }, 
      { id: 3, title: 'The Letters from No One', order: 2 }, 
      { id: 4, title: 'The Keeper of the Keys', order: 3 }, 
      { id: 5, title: 'Diagon Alley', order: 4 }, 
🕑 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.