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. 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

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 id="example">
  <panel v-if="!dragEvent" @switch="editMode = !editMode" :edit="editMode"></panel>
  <div class="row" id="lmdd-scope">
    <div class="col s12 m3 lmdd-block">
      <div class="black card mockup">
        <div class="card-content white-text">
          <span class="card-title">Add new card</span>
          <p>This is a demonstration of HTML editing and building tools using Vue (for reactivity), Materialize (for CSS) and LMDD (for drag & drop)</p>
        </div>
        <div class="card-action">
          <a class="mockup-fab btn-floating waves-effect waves-light red" @click="addNewCard"><i class="material-icons">add</i></a>
          <a href="https://vuejs.org/" target="_blank">Vue</a><a href="http://materializecss.com/" target="_blank">Materialize</a><a href="https://supraniti.github.io/Lean-Mean-Drag-and-Drop/" target="_blank">LMDD</a></div>
      </div>
    </div>
    <template v-for="(card,index) in cards">
    <card @context="apply" @removecard="removecard" :card="card" :index="index" :key="card"></card>
    </template>
  </div>
  <a class="waves-effect waves-light btn black" href="https://supraniti.github.io/Lean-Mean-Drag-and-Drop/" target="_blank">More Examples...</a>

  <div id="colorpalette" class="modal bottom-sheet">
    <div class="palette">
      <div v-for="color in colors" class="color" :class="color">
        <div class="title"></div>
        <div v-for="variant in colorVariants" class="sub-color waves-effect waves-light" :class="[color,variant]" @click="updatecolor(color,variant)"></div>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                html{
    overflow-y: scroll;
}
.palette{
  display:flex;
  flex-flow:row nowrap;
  width:100%;
  padding:15px;
}
.sub-color{
  transition: 0.2s;
/*   flex: 1 1 0px; */
}
.sub-color:hover{
  transform: rotateZ(5deg)
}
.color:hover .sub-color{
  flex: 1 1 auto;
  border:1px solid white;
}
.color{
  flex:1 1 auto;
  transition:0.3s;
  width:75px;
  height:75px;
/*   margin:15px; */
  display:flex;
  flex-flow:row nowrap;
}
.color:hover{
  width:100%;
}

.control{
  position:absolute;
  right:5px;
  top:5px;
  display:flex;
  flex-flow:row nowrap;
}
.control .btn-floating{
  margin:5px;
  opacity:0.6;
  width:24px;
  height:24px;
  line-height:24px;
  padding-top:2px;
}
.control .btn-floating i{
  position:absolute;
  font-size:20px;
  line-height:20px;
}
.control .btn-floating:hover{
  opacity:1;
  transform:rotate(-360deg);
}
.panel .btn-floating {
    width: 32px;
    height: 32px;
    line-height: 32px;
    padding:7px;
}
.panel .btn-floating i{
  position:absolute;  
  width: 18px;
    height: 18px;
    line-height: 18px;
  font-size:18px;
}
#example {
  padding:15px;
}

.panel {
  z-index: 1;
  transition: 0.3s;
  opacity: 0.75;
}

.panel .pulse {
  opacity: 0.5;
  transform:rotate(-360deg);
}

.panel .pulse:hover {
  opacity: 0.75;
}
/* .dragged > .card, .dragged > .card::before{
  transition:5s;
} */
.card {
  transition: transform 0.3s, opacity 0s;
}

.context > .card {
  transition:0.3s;
  transform: scale(1.1, 1.1);
}
.card::before{
  content:'';
  transform:translate3d(0px,0px,0px);
  transition:0.3s;
  opacity:0.5;
  display: block;
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background-color: inherit;
  border-radius: inherit;
  z-index: -1;
}
.edit > .card {
  box-shadow: 5px 5px 3px 0px rgba(0,0,0,0.75);
  opacity:1 !important;
}
.mockup::before{
  content:'';
  display:block;
  transform:rotate(2deg);
  width:100%;
  height:100%;
  background-color:inherit;
  border-radius:inherit;
}
.mockup{
  opacity:0.4;
  transform:rotate(-1deg);
}
.mockup:hover{
  opacity:0.8; 
  transform:rotate(0deg);
}
.mockup-fab{
  position:absolute;
  opacity:1;
  top:-20px;
  right:10px;
}
.lmdd-block{
  box-sizing:border-box;
}
              
            
!

JS

              
                 $(document).ready(function() {
   $('.modal').modal();
 });
 var defaultTitle = "Card Title";
 var defaultBody = "I am a very simple card. I am good at containing small bits of information, I am convenient because I require little markup to use effectively.";
 var defaultLink = "#";
 Vue.component('editable', {
   template: '<span v-bind:contenteditable="state" @input="update"></span>',
   props: ['content', 'ckey', 'state'],
   mounted: function() {
     this.$el.innerText = this.content[this.ckey];
   },
   methods: {
     update: function(event) {
       this.content[this.ckey] = event.target.innerText;
     }
   }
 });
 Vue.component('card', {
   template: '<div v-on:mouseover="contextme" class="col s12 m3 lmdd-block" :class="{context:isContext,edit:isEdit}"><div :class="card.color" class="card"><control v-if="isEdit" @delete="removeme" @invert="invertme"></control><div class="card-content" :class="isWhite"><editable class="card-title" :state="isEdit" :content="card" ckey="title"></editable><editable :state="isEdit" :content="card" ckey="body"></editable></div><div class="card-action"><a href="#">This is a link</a><a href="#">This is a link</a></div></div></div>',
   props: ['card', 'index'],
   computed: {
     isWhite: function() {
       return (this.card.white) ? 'white-text' : ''
     },
     isContext: function() {
       return (this.$root.$data.context === this);
     },
     isEdit: function() {
       return (this.$root.$data.editMode && this.isContext)
     }
   },
   methods: {
     invertme: function() {
       this.card.white = !this.card.white;
     },
     contextme: function() {
       this.$emit('context', this);
     },
     removeme: function() {
       this.$emit('removecard', this.index);
     }
   }
 });
 Vue.component('control', {
   template: '<div class="control">' +
     '<a @click="invert" class="btn-floating waves-effect waves-light black"><i class="material-icons">invert_colors</i></a>' +
     '<a href="#colorpalette" class="btn-floating waves-effect waves-light black"><i class="material-icons">palette</i></a>' +
     '<a @click="$emit(`delete`)"class="btn-floating waves-effect waves-light black"><i class="material-icons">delete_forever</i></a>' +
     '<a class="btn-floating waves-effect waves-light black"><i class="material-icons handle">open_with</i></a>' +
     '</div>',
   methods: {
     invert: function() {
       this.$emit('invert');
     }
   }
 });
 Vue.component('panel', {
   template: '<div class="panel" :style="style"><a class="btn-floating waves-effect waves-light black" :class="{pulse:!edit}" @click="toggleme"><i class="material-icons">build</i></a></div>',
   props: ['edit'],
   methods: {
     toggleme: function() {
       this.$emit('switch', this);
     }
   },
   computed: {
     style: function() {
       return {
         position: "absolute",
         transform: "translate3d(" + this.$root.rect.left + "," + this.$root.rect.top + ",0px)"
       }
     }
   }
 });
 var example = new Vue({
   el: '#example',
   data: {
     rect: {
       top: '',
       left: ''
     },
     editMode: false,
     dragEvent: false,
     context: {},
     cards: [],
     colors: ['purple', 'indigo', 'blue', 'green', 'yellow', 'orange', 'red'],
     colorVariants: ['darken-4', 'darken-3', 'darken-2', 'darken-1', '', 'lighten-1', 'lighten-2', 'lighten-3', 'lighten-4']
   },
   mounted: function() {
     lmdd.set(document.getElementById('lmdd-scope'), {
       containerClass: 'row',
       draggableItemClass: 'col',
       handleClass: 'handle',
       dataMode: true
     });
     this.$el.addEventListener('lmddend', this.handleDragEnd);
     this.$el.addEventListener('lmddstart', this.handleDragStart);
   },
   methods: {
     handleDragStart: function() {
       this.dragEvent = true;
     },
     handleDragEnd: function(event) {
       if (event.detail.to) {
         var newIndex = event.detail.to.index - 1;
         var oldIndex = event.detail.from.index - 1;
         this.cards.splice(newIndex, 0, this.cards.splice(oldIndex, 1)[0]);
         var component = event.detail.draggedElement.__vue__;
         this.context = component;
         this.rect.top = component.$el.getBoundingClientRect().top + window.pageYOffset - 15 + 'px';
         this.rect.left = component.$el.getBoundingClientRect().left + window.pageXOffset - 15 + 'px';
       }

       this.dragEvent = false;
     },
     updatecolor: function(color, variant) {
       this.context.card.color = color + ' ' + variant;
     },
     resetpanel: function() {
       this.editMode = false;
       this.context = {};
       this.rect.top = '-99999px';
     },
     removecard: function(event) {
       this.cards.splice(event, 1);
       this.resetpanel();
     },
     addNewCard: function() {
       this.cards.push({
         title: defaultTitle,
         body: defaultBody,
         white: true,
         color: this.colors[Math.floor(Math.random() * 5)]
       });
     },
     apply: function(component) {
       if ((this.context !== component) && (!this.editMode)) {
         this.context = component;
         this.rect.top = component.$el.getBoundingClientRect().top + window.pageYOffset - 15 + 'px';
         this.rect.left = component.$el.getBoundingClientRect().left + window.pageXOffset - 15 + 'px';
       }
     }
   }
 });
              
            
!
999px

Console