Carousel

A basic carousel component for looping through slides of images or text.

Basic Usage

Edit Banshee - Carousel

<banshee-carousel>
  <banshee-carousel-slide>
    content 1
  </banshee-carousel-slide>
  <banshee-carousel-slide>
    content 2
  </banshee-carousel-slide>
  <banshee-carousel-slide>
    content 3
  </banshee-carousel-slide>
</banshee-carousel>

The carousel requires two tags:

  • <banshee-carousel>
  • <banshee-carousel-slide>

The <banshee-carousel> tag marks an area as a Banshee carousel and provides the functionality for any child <banshee-carousel-slide> components to properly function. The <banshee-carousel-slide> must be a direct child of the <banshee-carousel> to be part of the "sliding" content.

As with everything Banshee, no CSS is being applied and no default transitions. You will have to provide your own.

With a custom transition:

<banshee-carousel transition-name="fade" 
                  transition-mode="out-in">
  <banshee-carousel-slide v-for="slide in slides" :key="slide.id">
    <img :src="slide.src">
  </banshee-carousel-slide>
</banshee-carousel>

<script>
// ...
slides: [
  { id: 1, src: 'https://picsum.photos/200?image=1074' },
  { id: 2, src: 'https://picsum.photos/200?image=876' },
  { id: 3, src: 'https://picsum.photos/200?image=1080' },
  { id: 4, src: 'https://picsum.photos/200?image=1011' },
  { id: 5, src: 'https://picsum.photos/200?image=995' }
]
</script>

<style>
.fade-enter-active, .fade-leave-active {
  transition: opacity .5s;
}
.fade-enter, .fade-leave-to {
  opacity: 0;
}
</style>

Attributes & Props

NameRequiredTypeDefaultDescription
autoplayfalseBooleanfalseautomatically loop through each slide
idfalseStringnullHTML id attribute to set on the carousel
pause-on-overfalseBooleanfalsewhether to pause the carousel on mouse hover
speedfalse[String, Number]5000time in ms for duration of each slide to display
start-slidefalse[String, Number]0which slide to start on
tagfalseStringulHTML tag for carousel
transition-appearfalseBooleanfalseappear property on Vue transition tag
transition-namefalseStringn/aname for your Vue transition
transition-modefalseStringn/amode for your Vue transition

Events

EventParametersDescription
onChangethe current index of the carouseltriggers when the carousel plays, pauses, or changes slides

Scoped Slots

PropertyDescription
activeIndexthe current active slide index
btnAttrs.buttonsaria labels for group of buttons that control slideshow
btnAttrs.nextaria labels for 'next' button
btnAttrs.pausearia labels for 'pause' button
btnAttrs.playaria labels for 'play' button
btnAttrs.previousaria labels for 'previous' button
lengthtotal number of slides in carousel
nextmethod to make the next slide active
pausemethod to pause the carousel if autoplaying
playmethod to play the carousel if paused
previousmethod to make the previous slide active

Attributes & Props

NameRequiredTypeDefaultDescription
tagfalseStringliHTML tag for carousel slide

More Examples

<banshee-carousel autoplay transition-name="fade" transition-mode="out-in">
  <banshee-carousel-slide>
    ...
  </banshee-carousel-slide>

  <banshee-carousel-slide>
    ...
  </banshee-carousel-slide>

  <banshee-carousel-slide>
    ...
  </banshee-carousel-slide>

  <template slot-scope="{ next, pause, play, previous, btnAttrs }">
    <button @click="previous" v-bind="btnAttrs.previous">Previous</button>
    <button @click="play" v-bind="btnAttrs.play">Play</button>
    <button @click="pause" v-bind="btnAttrs.pause">Pause</button>
    <button @click="next" v-bind="btnAttrs.next">Next</button>
  </template>
</banshee-carousel>

Bootstrap 4

Edit Banshee - Bootstrap 4 Carousel

<banshee-carousel autoplay transition-name="fade" transition-mode="out-in" tag="div" class="carousel slide">  
  <banshee-carousel-slide v-for="slide in slides" :key="slide.id" tag="div" class="carousel-inner">
    <div class="carousel-item active">
      <img class="d-block w-100" :src="slide.src">
    </div>
  </banshee-carousel-slide>

  <template slot-scope="{ next, pause, play, previous, btnAttrs }">
    <a class="carousel-control-prev" role="button"
        @click="previous" v-bind="btnAttrs.previous">
      <span class="carousel-control-prev-icon" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>

    <a class="carousel-control-next" role="button"
        @click="next" v-bind="btnAttrs.next">
      <span class="carousel-control-next-icon" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </template>
</banshee-carousel>   
Last Updated: 6/14/2018, 8:48:52 AM