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.carousel-wrapper#app
  div(class="carousel-inner" ref="carousel_inner")
    div(v-for="(item, index) in carousel" :key="index" class="carousel-item" :style="`width: ${itemWidth}px`")
      span {{ item.name }}
  button(@click="prev()" class="prev") &lt;
  button(@click="next()" class="next") &gt;
    
              
            
!

CSS

              
                * 
  box-sizing: border-box
.carousel-wrapper
  overflow: hidden
  position: relative
  .carousel-inner
    width: 100%
    display: flex
    justify-content: space-between
    flex-wrap: nowrap
    transition: all 1.2s ease-out 0s
    .carousel-item
      flex-shrink: 0
      height: 100vh
      display: flex
      justify-content: center
      align-items: center
      &:nth-child(odd)
        background: palegreen
      &:nth-child(even)
        background: skyblue
  button
    padding: 4px 12px
    font-size: 1.5em
    position: absolute
    top: 50%
    transform: translateY(-50%)
    border: none
    background: rgba(0,0,0,0.7)
    color: white
    &.prev
      left: 0
    &.next
      right: 0
              
            
!

JS

              
                const vueModel = new Vue({
  el: '#app',
  data() {
    return {
      carousel: [
        { name: 'カルーセル1' },
        { name: 'カルーセル2' },
        { name: 'カルーセル3' },
        { name: 'カルーセル4' },
        { name: 'カルーセル5' },
        { name: 'カルーセル6' },
        { name: 'カルーセル7' }
      ],
      itemWidth: 0,
      showPerView: 3,
      currentItem: 1,
      delay: 3000
    }
  },
  computed: {
    countItems() {
      return this.carousel.length + 1;
    },
    slideLength() {
      return this.itemWidth * this.currentItem
    }
  },
  mounted() {
    window.addEventListener('load', () => {
      this.init();
    })
    window.addEventListener('resize', () => {
      this.init();
    })
    this.start();
  },
  methods: {
    init() {
      this.itemWidth = this.$refs.carousel_inner.clientWidth / this.showPerView
    },
    slide() {
      this.$refs.carousel_inner.style.transform = `translateX(-${this.slideLength}px)`
    },
    start() {
      setInterval(() => {
        if (this.countItems - this.showPerView - 1 >= this.currentItem) {
          this.slide();
          this.currentItem++
        } else {
          this.$refs.carousel_inner.style.transform = `translateX(0)`
          this.currentItem = 1
        }
      }, this.delay)
    },
    prev() {
      if (0 < this.currentItem) {
        this.currentItem = this.currentItem - 1
        this.slide();
      }
    },
    next() {
      if (this.countItems - this.showPerView - 1 > this.currentItem) {
        this.currentItem = this.currentItem + 1
        this.slide();
      }
    }
  }
});
              
            
!
999px

Console