Vue.js Card Carousel For Web

Description:

A card carousel component for Vue.js that enables the user to switch between slides just like a stacked card.

How to use it:

1. Import the component & stylesheet into the project.

import { defineComponent } from 'vue'
import { CarouselCard, CarouselCardItem } from 'vue-carousel-card'
import 'vue-carousel-card/styles/index.css'

2. Register the component.

export default defineComponent({
  components: { CarouselCard, CarouselCardItem }
})

// OR
import CarouselCard from 'vue-carousel-card'
import 'vue-carousel-card/styles/index.css'
const app = createApp(App)
app.use(CarouselCard)
app.mount('#app')

3. Use the component.

<template>
  <CarouselCard ref="carouselCardRef" :interval="7000" :autoplay="false" height="260px" type="card" arrow="always" @change="changeHandle">
    <CarouselCardItem v-for="i in 6" :key="i" :name="`cc_${i}`">
      <h1 v-text="i"></h1>
    </CarouselCardItem>
  </CarouselCard>
  <div style="text-align: center; padding: 10px">
    <button @click="prev">prev</button>
    <button @click="next">next</button>
    <button @click="setToFirst">set to first</button>
  </div>
  <CarouselCard :interval="3000" height="300px" :autoplay="false" arrow="always" direction="vertical">
    <CarouselCardItem v-for="i in 6" :key="i">
      <h1 v-text="i"></h1>
    </CarouselCardItem>
  </CarouselCard>
</template>
import { defineComponent, ref } from 'vue'
import { ICarouselCard } from 'vue-carousel-card'
export default defineComponent({
  setup () {
    const carouselCardRef = ref<ICarouselCard>()
    const changeHandle = (index: number) => {
      console.log(index)
    }
    const next = () => {
      carouselCardRef.value?.next()
    }
    const prev = () => {
      carouselCardRef.value?.prev()
    }
    const setToFirst = () => {
      carouselCardRef.value?.setActiveItem(0)
    }
    return {
      carouselCardRef,
      changeHandle,
      next,
      prev,
      setToFirst
    }
  }
})

4. Props for the carousel card

initialIndex: number
height: string
trigger: string
autoplay: boolean
interval: number
indicatorPosition: string
indicator: boolean
arrow: string
type: string
loop: boolean
direction: string
pauseOnHover: boolean

5. Props for carousel items.

key?: string
name: string
label: string | number

6. API methods.

// set active carousel item
setActiveItem(index)

// back to the prev
prev()

// go to the next
next()

Preview:

Vue.js Card Carousel For Web

Changelog:

v2.0.0 (06/23/2021)

  • Updated for Vue 3

Download Details:

Author: jekorx

Live Demo: https://jekorx.github.io/vue-carousel-card/

Download Link: https://github.com/jekorx/vue-carousel-card/archive/master.zip

Official Website: https://github.com/jekorx/vue-carousel-card

Install & Download:

# Yarn
$ yarn add vue-carousel-card

# NPM
$ npm install vue-carousel-card --save

You Might Be Interested In:

Add Comment