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

              
                script#carousel(type="x/template")
  div.card-carousel-wrapper
    div.card-carousel--nav__left(@click="moveCarousel(-1)" :disabled="atHeadOfList")
    div.card-carousel
      div.card-carousel--overflow-container
        div.card-carousel-cards(:style="{ transform: 'translateX' + '(' + currentOffset + 'px' + ')'}")
          div.card-carousel--card(v-for="item in items")
            img(:src="'https://picsum.photos/id/3' + item.name + '/200/200'" :alt="item.name")
            div.card-carousel--card--footer {{ item.name }}
    div(class="card-carousel--nav__right" @click="moveCarousel(1)" :disabled="atEndOfList")
div#app
  carousel
              
            
!

CSS

              
                *
  margin: 0
  padding: 0
  box-sizing: border-box
  
body
  display: flex
  min-height: 100vh
  align-items: center
  justify-content: center
  background: #eee

.card-carousel-wrapper
  display: flex
  align-items: center
  justify-content: center
  margin: 20px 0 40px

.card-carousel
  display: flex
  justify-content: center
  width: 640px
  
  &--overflow-container
    overflow: hidden
  
  &--nav__left,
  &--nav__right
    display: inline-block
    width: 15px
    height: 15px
    padding: 10px
    box-sizing: border-box
    border-top: 2px solid #000
    border-right: 2px solid #000
    cursor: pointer
    margin: 0 20px
    transition: transform .8s cubic-bezier(0.430, 0.195, 0.020, 1.000)
    &[disabled]
      opacity: 0.2
      border-color: black
  
  &--nav__left
    transform: rotate(-135deg)
    &:active
      transform: rotate(-135deg) scale(0.9)

  &--nav__right
    transform: rotate(45deg)
    &:active
      transform: rotate(45deg) scale(0.9)

.card-carousel-cards
  white-space: nowrap
  transition: transform .8s cubic-bezier(0.430, 0.195, 0.020, 1.000)
  transform: translatex(0px)
 
  .card-carousel--card
    width: 200px
    display: inline-block
    vertical-align: top
    margin: 0 10px
    background-color: #fff
    
    &:first-child
      margin-left: 0
    
    &:last-child
      margin-right: 0
    
    img
      display: block
      width: 100%
      height: auto
    
    &--footer
      padding: 10px
              
            
!

JS

              
                class Item {
  constructor(name) {
    this.name = name
  }
}

Vue.component("carousel", {
  template: "#carousel",
  data() {
    return {
      currentOffset: 0,
      windowSize: 2,
      paginationFactor: 220,
      items: [
        new Item('1'),
        new Item('2'),
        new Item('3'),
        new Item('4'),
        new Item('5'),
        new Item('6'),
        new Item('7'),
        new Item('8'),
        new Item('9')
      ]
    }
  },
  computed: {
    atEndOfList() {
      return this.currentOffset <= (this.paginationFactor * -1) * ((this.items.length - 1) - this.windowSize)
    },
    atHeadOfList() {
      return this.currentOffset === 0
    }
  },
  methods: {
    moveCarousel(direction) {
      if (direction === 1 && !this.atEndOfList) {
        this.currentOffset -= this.paginationFactor
      } else if (direction === -1 && !this.atHeadOfList) {
        this.currentOffset += this.paginationFactor
      }
    }
  }
})

new Vue({
  el:"#app"
})
              
            
!
999px

Console