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">
  <!-- 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>
            
          
!
            
              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); }
}
            
          
!
            
              // 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
🕑 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.

Console