Convert Figma logo to code with AI

lukaszflorczak logovue-agile

🎠 A carousel component for Vue.js

1,490
168
1,490
56

Top Related Projects

39,745

Most modern mobile touch slider with hardware accelerated transitions

28,515

the last carousel you'll ever need

React carousel component

Vanilla javascript slider for all purposes.

4,864

Splide is a lightweight, flexible and accessible slider/carousel written in TypeScript. No dependencies, no Lighthouse errors.

Quick Overview

Vue-agile is a lightweight and responsive carousel component for Vue.js applications. It provides a simple and customizable way to create image sliders and content carousels with touch support and various navigation options.

Pros

  • Easy to integrate and use with Vue.js projects
  • Responsive design with support for mobile devices and touch gestures
  • Customizable with various options for navigation, autoplay, and styling
  • Lightweight and performant

Cons

  • Limited built-in transition effects compared to some other carousel libraries
  • Documentation could be more comprehensive, especially for advanced use cases
  • May require additional styling effort to achieve complex designs

Code Examples

  1. Basic usage:
<template>
  <agile>
    <div class="slide">
      <img src="image1.jpg" alt="Slide 1">
    </div>
    <div class="slide">
      <img src="image2.jpg" alt="Slide 2">
    </div>
    <div class="slide">
      <img src="image3.jpg" alt="Slide 3">
    </div>
  </agile>
</template>

<script>
import { VueAgile } from 'vue-agile'

export default {
  components: {
    agile: VueAgile
  }
}
</script>
  1. With custom navigation:
<template>
  <agile :nav-buttons="false">
    <div class="slide" v-for="n in 5" :key="n">Slide {{ n }}</div>

    <template slot="prevButton">Prev</template>
    <template slot="nextButton">Next</template>
  </agile>
</template>
  1. Responsive settings:
<template>
  <agile :options="options">
    <div class="slide" v-for="n in 8" :key="n">Slide {{ n }}</div>
  </agile>
</template>

<script>
export default {
  data() {
    return {
      options: {
        responsive: [
          {
            breakpoint: 600,
            settings: {
              slidesToShow: 2,
            },
          },
          {
            breakpoint: 900,
            settings: {
              slidesToShow: 3,
            },
          },
        ],
      },
    }
  },
}
</script>

Getting Started

  1. Install the package:

    npm install vue-agile
    
  2. Import and use in your Vue component:

    <template>
      <agile>
        <div class="slide">1</div>
        <div class="slide">2</div>
        <div class="slide">3</div>
      </agile>
    </template>
    
    <script>
    import { VueAgile } from 'vue-agile'
    
    export default {
      components: {
        agile: VueAgile
      }
    }
    </script>
    
  3. Add required styles:

    <style>
    @import 'vue-agile/dist/style.css';
    </style>
    

Competitor Comparisons

39,745

Most modern mobile touch slider with hardware accelerated transitions

Pros of Swiper

  • More comprehensive feature set, including 3D effects, parallax, and virtual slides
  • Better performance for complex layouts and large numbers of slides
  • Wider browser compatibility, including older versions of Internet Explorer

Cons of Swiper

  • Larger file size, which may impact page load times
  • Steeper learning curve due to more complex API and configuration options
  • Not specifically designed for Vue.js, requiring additional setup for integration

Code Comparison

Vue-agile (Vue.js specific):

<template>
  <agile>
    <div class="slide">Slide 1</div>
    <div class="slide">Slide 2</div>
    <div class="slide">Slide 3</div>
  </agile>
</template>

Swiper (Generic JavaScript):

const swiper = new Swiper('.swiper-container', {
  slidesPerView: 3,
  spaceBetween: 30,
  pagination: {
    el: '.swiper-pagination',
    clickable: true,
  },
});

Both libraries offer smooth sliding functionality, but Vue-agile provides a more Vue-centric approach with easier integration into Vue.js projects. Swiper, on the other hand, offers more advanced features and customization options at the cost of increased complexity and file size.

28,515

the last carousel you'll ever need

Pros of Slick

  • More mature and widely adopted, with a larger community and ecosystem
  • Supports a broader range of browsers, including older versions
  • Offers more customization options and features out of the box

Cons of Slick

  • Requires jQuery as a dependency, which may increase bundle size
  • Not specifically designed for Vue.js, potentially leading to integration challenges
  • Less frequently updated compared to Vue Agile

Code Comparison

Vue Agile:

<template>
  <agile>
    <div class="slide">Slide 1</div>
    <div class="slide">Slide 2</div>
    <div class="slide">Slide 3</div>
  </agile>
</template>

Slick:

<div class="slider">
  <div>Slide 1</div>
  <div>Slide 2</div>
  <div>Slide 3</div>
</div>

<script>
  $(document).ready(function(){
    $('.slider').slick();
  });
</script>

The code comparison shows that Vue Agile integrates more seamlessly with Vue.js components, while Slick requires jQuery initialization. Vue Agile's syntax is more declarative and Vue-friendly, whereas Slick follows a more traditional jQuery plugin approach.

React carousel component

Pros of react-slick

  • More mature and widely adopted in the React ecosystem
  • Extensive customization options and API
  • Supports a wider range of features, including vertical sliding and center mode

Cons of react-slick

  • Larger bundle size due to additional dependencies
  • Steeper learning curve for complex configurations
  • Less frequent updates and maintenance compared to vue-agile

Code Comparison

vue-agile:

<agile>
  <div class="slide">Slide 1</div>
  <div class="slide">Slide 2</div>
  <div class="slide">Slide 3</div>
</agile>

react-slick:

<Slider>
  <div>Slide 1</div>
  <div>Slide 2</div>
  <div>Slide 3</div>
</Slider>

Both libraries offer similar basic usage, with vue-agile using the <agile> component and react-slick using the <Slider> component. The main difference lies in the framework-specific implementation and available props for customization.

react-slick provides more advanced features and customization options out of the box, while vue-agile focuses on simplicity and ease of use for Vue.js projects. The choice between the two depends on the specific project requirements, framework preference, and desired level of customization.

Vanilla javascript slider for all purposes.

Pros of tiny-slider

  • Framework-agnostic, can be used with any JavaScript project
  • Smaller bundle size, potentially better performance
  • More customization options and features out of the box

Cons of tiny-slider

  • Requires more manual setup and configuration
  • Less Vue-specific optimizations and integrations
  • May require additional work to achieve reactive data binding

Code Comparison

tiny-slider:

var slider = tns({
  container: '.my-slider',
  items: 3,
  slideBy: 'page',
  autoplay: true
});

vue-agile:

<template>
  <agile :options="{ slidesToShow: 3, autoplay: true }">
    <div class="slide">...</div>
    <div class="slide">...</div>
    <div class="slide">...</div>
  </agile>
</template>

tiny-slider offers a more traditional JavaScript approach, while vue-agile provides a Vue-specific component with built-in reactivity. tiny-slider requires manual DOM selection and initialization, whereas vue-agile integrates seamlessly with Vue's template syntax and component system.

tiny-slider's flexibility makes it suitable for a wider range of projects, but vue-agile offers a more streamlined experience for Vue developers. The choice between the two depends on the specific project requirements, developer preferences, and the importance of Vue integration.

4,864

Splide is a lightweight, flexible and accessible slider/carousel written in TypeScript. No dependencies, no Lighthouse errors.

Pros of Splide

  • Framework-agnostic, can be used with any JavaScript framework or vanilla JS
  • More extensive documentation and examples
  • Supports a wider range of features, including video carousels and nested sliders

Cons of Splide

  • Larger file size compared to Vue Agile
  • Steeper learning curve due to more configuration options
  • Not specifically optimized for Vue.js integration

Code Comparison

Vue Agile:

<agile>
  <div class="slide">Slide 1</div>
  <div class="slide">Slide 2</div>
  <div class="slide">Slide 3</div>
</agile>

Splide:

<div class="splide">
  <div class="splide__track">
    <ul class="splide__list">
      <li class="splide__slide">Slide 1</li>
      <li class="splide__slide">Slide 2</li>
      <li class="splide__slide">Slide 3</li>
    </ul>
  </div>
</div>

Summary

Splide offers a more versatile and feature-rich carousel solution suitable for various projects, while Vue Agile provides a simpler, Vue-specific implementation. Splide's framework-agnostic nature and extensive documentation make it a strong choice for complex projects, but it comes with a larger file size and potentially more complex setup. Vue Agile, on the other hand, offers a more straightforward integration for Vue.js projects with a smaller footprint.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

vue-agile

A carousel component for Vue.js inspired by Slick.
Powerful, responsive, touch-friendly, with Nuxt.js SSR support, without a jQuery dependency.

Demo & examples

More demos and examples coming soon in vue-agile CodePens collection.


If you like the component remember to star it ⭐️. If you appreciate my work you can also buy me a coffee ☕️ 😉


🔭 If you're looking for Vue 2 version, check legacy/vue-v2 branch.

Installation

npm install vue-agile

or

yarn add vue-agile

Styles

The component is delivered without styles for the appearance of the navigation elements (like dots color and shape, arrows position, etc.). I think most people use their own styles and default styles are completely redundant. If you want, feel free to use styles from CodePen demos.

Importing

Global

// main.js
import { createApp } from 'vue'
import App from './App.vue'
import VueAgile from 'vue-agile'

createApp(App)
  .use(VueAgile)

In component

// YourComponent.vue
import { VueAgile } from 'vue-agile'

export default {
  components: {
    agile: VueAgile
  }
}

Via <script>

<script src="https://unpkg.com/vue-agile"></script>
<link rel="stylesheet" href="https://unpkg.com/vue-agile/dist/VueAgile.css">

Usage

<template>
  <agile>
    <div class="slide">
      <h3>slide 1</h3>
    </div>

    ...

    <div class="slide">
      <h3>slide n</h3>
    </div>
  </agile>
</template>

Every first-level child of <agile> is a new slide. You also can group them inside <template v-slot:default>...</template> tags.

Options / Props

ParameterTypeDefaultDescription
asNavForarray[]Set the carousel to be the navigation of other carousels
autoplaybooleanfalseEnable autoplay
autoplaySpeedinteger (ms)3000Autoplay interval in milliseconds
centerModebooleanfalseEnable centered view when slidesToShow > 1
changeDelayinteger (ms)0Insert a delay when switching slides. Useful for fade: true
dotsbooleantrueEnable dot indicators/pagination
fadebooleanfalseEnable fade effect
infinitebooleantrueInfinite loop sliding
initialSlideinteger0Index of slide to start on
mobileFirstbooleantrueEnable mobile first calculation for responsive settings
navButtonsbooleantrueEnable prev/next navigation buttons
optionsobjectnullAll settings as one object
pauseOnDotsHoverbooleanfalsePause autoplay when a dot is hovered
pauseOnHoverbooleantruePause autoplay when a slide is hovered
responsiveobjectnullObject containing breakpoints and settings objects
rtlbooleanfalseEnable right-to-left mode
slidesToShowinteger1Number of slides to show
speedinteger (ms)300Slide animation speed in milliseconds
swipeDistanceinteger (px)50Distance to swipe the next slide
throttleDelayinteger (ms)500Throttle delay for actions
timingstringeaseTransition timing function
(linear/ease/ease-in/ease-out/ease-in-out)
unagilebooleanfalseDisable Agile carousel

Example

<agile :dots="false" :infinite="false" :autoplay-speed="5000">...</agile>

Important! If you use props inline, convert props names from camelCase to kebab-case.

Methods

NameDescription
getCurrentBreakpoint()Returns current breakpoint (can returns 0 in mobile first for the smallest breakpoint and null for desktop first for the largest)
getCurrentSettings()Returns settings object for current breakpoint – useful for debugging
getCurrentSlide()Returns index of current slide
getInitialSettings()Returns full settings object with all options – useful for debugging
goTo()Navigates to a slide by index
goToNext()Navigates to next slide
goToPrev()Navigate to previous slide
reload()Reload carousel & slides settings, classes and inline styles

Example

<agile ref="carousel">...</agile>

<button @click="$refs.carousel.goToNext()">My custom button</button>

Events

NameValueDescription
after-change{ currentSlide }Fires after slide change
before-change{ currentSlide, nextSlide }Fires before slide change
breakpoint{ breakpoint } Fires after breakpoint change

Example

<agile @after-change="showCurrentSlide($event)">...</agile>
showCurrentSlide(event)
{
  console.log(event)
  // Shows for example: { currentSlide: 1 }
}

Responsive

To customize responsiveness, I recommend defining your desired breakpoints and passing settings object with your modification options inside options.

Example

<agile :options="myOptions">...</agile>
data()
{
  return {
    myOptions: {
      navButtons: false,
      responsive: [
        {
          breakpoint: 600,
          settings: {
            dots: false
          }
        },

        {
          breakpoint: 900,
          settings: {
            navButtons: true,
            dots: true,
            infinite: false
          }
        }
      ]
    }
  }
}

How does it work? Mobile first mode is used by default. It means, that navButtons: false option will be used on screens from 0 to 600 px width (+ all default carousel options). On screens from 600 to 900 px dots: false will be added to options from breakpoint before. And on screens over 900 px width navButtons and dots options will be overwritten and infinite: false will be added.

Custom arrows / nav buttons

From version 1.0 the component use slots for custom navigation buttons. It means you can put inside whatever you want – any HTML with text, image, icon etc.

Example

<agile>
... <!-- slides -->

<template slot="prevButton">prev</template>
<template slot="nextButton">next</template>
</agile>

Caption

To display a static caption or such like within the gallery, you can use the caption slot.

Example

<agile @after-change="e => currentSlide = e.currentSlide">
  ... <!-- slides -->

  <template slot="caption">{{ captions[currentSlide] }}</template>
</agile>

<script>
  export default {
    data () {
      return {
        currentSlide: 0,
        captions: [
          'This is slide 1',
          'This is the second slide',
          'This is a third and final slide',
        ]
      }
    }
  }
</script>

asNavFor

This option is useful for example for creating a photo gallery with two related slider – one big with only one slide in view and second for navigation with thumbnails.

Example

<agile ref="main" :fade="true">...</agile>

<agile ref="thumbnails" :as-nav-for="[$refs.main]" :slides-to-show="4" autoplay>...</agile>

Important! If you want to use the autoplay mode use it only in one of the related carousels.

v-if & v-show

If you have slides being dynamically loaded, use v-if to show the carousel after the slides are ready. Using v-if is also recommended in other situations if you want to hide/show the slideshow.

It is also possible to use v-show, but you have to use the reload() method.

Example

<button @click="isActive = !isActive">Toggle carousel</button>

<agile v-if="isActive">...</agile>

Nuxt.js && SSR Support

The component uses browser specific attributes (like window and document). However, you can try to render the first view on server side.

Example

// plugins/vue-agile.js

import Vue from 'vue'
import VueAgile from 'vue-agile'

Vue.use(VueAgile)
// nuxt.config.js

export default {
  plugins: ['~/plugins/vue-agile'],

  build: {
    transpile: ['vue-agile']
  }
}

To use component without SSR use the client-only component:

<client-only placeholder="Loading...">
  <agile>...</agile>
</client-only>

Important! Component rendered on server side has additional CSS class: agile--ssr, so you can use it to add some additional styles or manipulations. For example, I have limited options for setting the first appearance of the slides. By default, the server renders the view and styles, where only the first slide is visible.

.agile--ssr .agile__slides > * {
  overflow: hidden;
  width: 0
}

.agile--ssr .agile__slides > *:first-child {
  width: 100%
}

At this stage slides don't have agile__slide class yet, so I use > * instead of this.

If you would like to connect this with params slidesToShow or initialSlide you have to add some custom styles with nth-child param.

Example for :slidesToShow="2"

.agile--ssr
  .agile__slides
    > *:nth-child(1),
    > *:nth-child(2)
      width: 50%

Example for :initialSlide="1"

(Slides index starts at 0)

.agile--ssr
  .agile__slides
    > *:nth-child(1)
      width: 0

    > *:nth-child(2)
      width: 100%

You can also check nuxt-agile repository and check working demo of vue-agile with Nuxt and SSR.

FAQ

1. Using component with dynamic content

If content changes, you have to use reload or in some cases, you can use key property: <agile :key="mySlides.length">...</agile> (it'll rebuild the carousel after each change of mySlides length).

2. Support for IE11

Yes, the UMD bundle is built with support for IE11. If you build your app with vue-agile as a dependency yourself be sure you configured babel properly (read more in vue documentation or just use my config for babel).

NPM DownloadsLast 30 Days