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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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="app">
  <!-- name attribute is bound, transition name is changed on button clicking -->
  <transition :name="currentTransition" mode="out-in">
    <!-- is attribute is bound, current slide is changed via updating a variable to reference an array of strings -->
    <component :is="slides[currentSlide]"></component>
  </transition>
   
  <div id="panel">
    <!-- disables if currentSlide is first entry of slides array -->
    <!-- click event passes which direction to one method -->
    <button :class="{disabled: currentSlide === 0}" @click="changeSlide('prev')">prev</button>
    <!-- keep track of where we are and total slides -->
    <div>{{ currentSlide + 1}} of {{ slides.length }}</div>
    <!-- disables if currentSlide is at end of slides array -->
    <!-- click event passes which direction to one method -->
    <button :class="{disabled: currentSlide === slides.length - 1}" @click="changeSlide('next')">next</button>
  </div>
</div>
              
            
!

CSS

              
                body {
  background-image: radial-gradient(ellipse at center, rgba(98,125,77,1) 0%,rgba(31,59,8,1) 100%);
  background-repeat: no-repeat;
  background-size: cover;
  height: 100vh;
  overflow: hidden;
  width: 100vw;
}

#app {
  align-items: center;
  display: flex;
  height: 100%;
  justify-content: center;
  width: 100%;
}

#panel {
  align-items: stretch;
  bottom: 0;
  color: white;
  display: flex;
  font-family: sans-serif;
  position: absolute;
  width: 100%;
  
  button {
    background-color: rgba(0, 0, 0, 0.25);
    border: {
      color: white;
      radius: 7px;
      style: solid;
      width: 2px;
    }
    color: white;
    cursor: pointer;
    flex-grow: 1;
    font-size: 24px;
    margin: 20px;
    
    &.disabled {
      opacity: 0.5;
      pointer-events: none;
    }
  }
  div {
    align-items: center;
    display: flex;
    font-size: 24px;
  }
}

.slide {
  align-items: center;
  background-color: rebeccapurple;
  border: 3px solid darken(rebeccapurple, 25);
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.5);
  color: white;
  display: flex;
  font-family: sans-serif;
  font-size: 20px;
  height: 200px;
  justify-content: center;
  width: 400px;
}

// prefixed with "next" so the next button easily changes to this block of CSS
.next-enter { opacity: 0; transform: scale3d(2, 0.5, 1) translate3d(400px, 0, 0); }
.next-enter-to { transform: scale3d(1, 1, 1); }
.next-enter-active,
.next-leave-active { transition: 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55); }
.next-leave { transform: scale3d(1, 1, 1); }
.next-leave-to { opacity: 0; transform: scale3d(2, 0.5, 1) translate3d(-400px, 0, 0); }

// prefixed with "prev" so the prev button easily changes to this block of CSS
.prev-enter { opacity: 0; transform: scale3d(2, 0.5, 1) translate3d(-400px, 0, 0); }
.prev-enter-to { transform: scale3d(1, 1, 1); }
.prev-enter-active,
.prev-leave-active { transition: 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55); }
.prev-leave { transform: scale3d(1, 1, 1); }
.prev-leave-to { opacity: 0; transform: scale3d(2, 0.5, 1) translate3d(400px, 0, 0); }

// if animations are reduced at the OS level, use simpler transitions
@media screen and (prefers-reduced-motion: reduce) {
  .next-enter { opacity: 0; transform: translate3d(100px, 0, 0); }
  .next-enter-active,
  .next-leave-active { transition: 0.5s; }
  .next-leave-to { opacity: 0; transform: translate3d(-100px, 0, 0); }
  
  .prev-enter { opacity: 0; transform: translate3d(-100px, 0, 0); }
  .prev-enter-active,
  .prev-leave-active { transition: 0.5s; }
  .prev-leave-to { opacity: 0; transform: translate3d(100px, 0, 0); }
}
              
            
!

JS

              
                // these are the two components I'm constantly switching between for this demo
// depending on the situation, the content of the components can be changed dynamically
// or you could just create a component for each slide, up to you
Vue.component('slideA', {
	template: '<div class="slide"><span>This is slide A</span></div>'
});
Vue.component('slideB', {
	template: '<div class="slide"><span>This is slide B</span></div>'
});

new Vue({
  el: "#app",
  data: {
    // this array is to track the current slide and to dictate the order of appearance
  	slides: ['slideA', 'slideB', 'slideA', 'slideB'],
    // number to reference the index of the slides array
    currentSlide: 0,
    // string to pass to component element in the bound is attribute
    currentTransition: ''
  },
  methods: {
    // method called when next or prev buttons are clicked
    // direction is passed as parameter
  	changeSlide: function (dir) {
      // simple test against dir string
      // if "next" then increase currentSlide by 1, otherwise decrease by 1
      // would be really easy to create a rule to go to first or last slide as well
    	this.currentSlide = dir === 'next' ? this.currentSlide + 1 : this.currentSlide - 1;
      // just give the dir string because the CSS transitions are prefixed with "next" and "prev"
    	this.currentTransition = dir;
    }
  }
});
              
            
!
999px

Console