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

              
                <h1>Welcome to Vue!</h1>

<h2>Custom Directives</h2>

<div id="my-app">

 <div class="scrollable-container">
  <!-- v-pin is the custom directive we created -->
  <div v-pin>😯</div>

  <!-- v-pin2 is a slight modification to it, so that we can see how we can pass an argument and also  the other hooks -->
  <div v-if="display" v-pin2:dark>😁</div>

  <p>Single-origin coffee kogi coloring book etsy everyday carry mumblecore health goth, scenester vice literally.
   Tumblr twee hoodie, tacos dreamcatcher keytar banh mi gentrify.</p>

  <p>Keytar paleo shoreditch pork belly you probably haven't heard of them gentrify migas iceland street art locavore
   four dollar toast seitan cray DIY. Coloring book hexagon tbh occupy.</p>

  <p>Biodiesel next level flexitarian, pickled tumblr pork belly venmo adaptogen pop-up poke master cleanse offal tote
   bag. Squid lumbersexual lo-fi tote bag locavore next level. </p>

  <!-- This is so we can see how the `update` and `unbind` hooks work-->
  <p v-if="display">
   Af narwhal raclette vexillologist. Ethical meh sriracha freegan normcore. Live-edge fingerstache chia synth.
   Asymmetrical raclette you probably haven't heard of them, photo booth mlkshk selvage helvetica leggings shoreditch
   thundercats pickled bicycle rights quinoa narwhal.
   https://hipsum.co/
  </p>
 </div>
 <!-- With this we add and remove the directive (and modify the containing node) -->
 <button @click="display = !display">Toggle</button>
</div>
              
            
!

CSS

              
                $primary: #41b883;
$secondary: #34495e;

body {
 background-color: whitesmoke;
 color: $secondary;
 font-family: sans-serif;
 padding: 10px;
}

h1 {
 margin: 0 auto;
 width: 80%;
 text-align: center;
}

h2,
h3 {
 color: $primary;
}

#my-app {
 width: 80%;
 margin: 0 auto;
}

input[type="text"] {
 color: $secondary;
 font-size: 1em;
 min-width: 250px;
 background: transparent;
 margin-bottom: 20px;
}

.answer {
 color: $primary;
}

.colored {
 background-color: $secondary;
 color: $primary;
}

hr {
 border: 1px solid $secondary;
 margin-top: 20px;
}

.off-limits {
 background: tomato;
 width: 100px;
 height: 100px;
 color: whitesmoke;
 font-weight: bold;
}

button {
 background-color: whitesmoke;
 color: #34495e;
 margin: 10px 0;
 padding: 5px;
}

/* component styles */
.card {
 display: flex;
 align-items: center;
 justify-content: space-around;
 box-shadow: 3px 4px 25px -4px rgba(0, 0, 0, 0.38);
 margin: 15px 0;
 padding: 5px;
 background-color: lightgoldenrodyellow;

 img {
  width: 100px;
  box-shadow: 5px 4px 25px -4px rgba(0, 0, 0, 0.38);
 }

 p {
  margin: 10px;
 }

 .label {
  font-weight: bold;
 }

 .value {
  font-style: italic;
 }
}

.scrollable-container {
 height: 200px; 
 border: 2px solid #34495e; 
 overflow-y: scroll;
}
              
            
!

JS

              
                // registering a directive
Vue.directive('pin', {
 // hook functions can be used to define the behavior of the directive
 bind(el, binding, vnode) {
  
  console.log('pin was bound!', el);
  
  var size = binding.value || 40;

  el.style.position = 'fixed';
  el.style.background = '#41b883';
  el.style.textAlign = 'center';
  el.style.color = 'whitesmoke';
  
  el.style.width = size + 'px';
  el.style.height = size + 'px';
  el.style.borderRadius = size + 'px';
  el.style.lineHeight = size + 7 + 'px'; // emoji need to be pushed down a bit
  
  },
 // all of the hooks receive `el`, `binding`, `vnode` as arguments
 inserted(el, binding, vnode){
  console.log(el, 'inserted!')
 },
 // but `update` for example has both the old VNode and the new one
 update(el, binding, oldVnode, newVnode) {
  console.log(oldVnode, 'updated to', newVnode)
 },
 componentUpdated() {
  console.log('component updated');
 }
});

// we want to push this to the right a bit
// but it is the same idea
// not exactly DRY, I know
Vue.directive('pin2', {
 bind(el, binding, vnode) {
  
  console.log('pin2 was bound!', el);
  var size = binding.value || 40;
  var bg = binding.arg && binding.arg == 'dark' ? '#34495e' : '#41b883';
  
  el.style.position = 'fixed';
  el.style.left = '260px';
  el.style.background = bg;
  
  el.style.textAlign = 'center';
  el.style.color = 'whitesmoke';
  
  el.style.width = size + 'px';
  el.style.height = size + 'px';
  el.style.borderRadius = size + 'px';
  el.style.lineHeight = size + 7 + 'px'; // emoji need to be pushed down a bit
  
  },
 inserted(el, binding, vnode){
  console.log(el, 'inserted!')
 },
 // this directive has a hook to know when it will go away
 unbind() {
  console.log('unbound, See You Space Cowboy!')
 }
});

new Vue({ 
    el: '#my-app',
    data: {
        display: true
    }
});

              
            
!
999px

Console