Categories
Vue

Vueper Slides Library — Customize Slides

With the Vueper Slides library, we can add a carousel to our Vue app easily.

In this article, we’ll look at how to use it to add a carousel to our Vue app.

Fractions and Progress

We can show the progress of the slide with the fractions and progress props:

<template>
  <div id="app">
    <vueper-slides fractions progress>
      <vueper-slide v-for="i in 10" :key="i" :title="i.toString()"/>
    </vueper-slides>
  </div>
</template>

<script>
import { VueperSlides, VueperSlide } from "vueperslides";
import "vueperslides/dist/vueperslides.css";

export default {
  name: "App",
  components: { VueperSlides, VueperSlide }
};
</script>

We’ll see a progress bar displayed.

Images and Fading

We can add images and fading effects in our slides with the image prop:

<template>
  <div id="app">
    <vueper-slides fade :touchable="false">
      <vueper-slide
        v-for="(slide, i) in slides"
        :key="i"
        :image="slide.image"
        :title="slide.title"
        :content="slide.content"
      />
    </vueper-slides>
  </div>
</template>

<script>
import { VueperSlides, VueperSlide } from "vueperslides";
import "vueperslides/dist/vueperslides.css";

export default {
  name: "App",
  components: { VueperSlides, VueperSlide },
  data() {
    return {
      slides: Array(5)
        .fill()
        .map((_, i) => ({
          title: `title ${i}`,
          content: `content ${i}`,
          image: `https://picsum.photos/id/${i + 1}/400/300`
        }))
    };
  }
};
</script>

We set the image prop to the URL for our images.

Also, we added the fade effect with the fade prop.

touchable is set to false to disable changing slides with touch.

Lazy Loading

We can lazy load our slides with the lazy and lazy-load-on-drag props.

Then we populate the loader slot with the loading indicator of our choice:

<template>
  <div id="app">
    <vueper-slides lazy lazy-load-on-drag>
      <vueper-slide
        v-for="(slide, i) in slides"
        :key="i"
        :image="slide.image"
        :title="slide.title"
        :content="slide.content"
      />
      <template v-slot:loader>
        <span>Loading...</span>
      </template>
    </vueper-slides>
  </div>
</template>

<script>
import { VueperSlides, VueperSlide } from "vueperslides";
import "vueperslides/dist/vueperslides.css";

export default {
  name: "App",
  components: { VueperSlides, VueperSlide },
  data() {
    return {
      slides: Array(5)
        .fill()
        .map((_, i) => ({
          title: `title ${i}`,
          content: `content ${i}`,
          image: `https://picsum.photos/id/${i + 1}/400/300`
        }))
    };
  }
};
</script>

Link on the Whole Slide

We can make the slides have links with the link prop.

For example, we can write:

<template>
  <div id="app">
    <vueper-slides lazy lazy-load-on-drag>
      <vueper-slide
        v-for="(slide, i) in slides"
        :key="i"
        :image="slide.image"
        :title="slide.title"
        :content="slide.content"
        :link="slide.image"
      />
      <template v-slot:loader>
        <span>Loading...</span>
      </template>
    </vueper-slides>
  </div>
</template>

<script>
import { VueperSlides, VueperSlide } from "vueperslides";
import "vueperslides/dist/vueperslides.css";

export default {
  name: "App",
  components: { VueperSlides, VueperSlide },
  data() {
    return {
      slides: Array(5)
        .fill()
        .map((_, i) => ({
          title: `title ${i}`,
          content: `content ${i}`,
          image: `https://picsum.photos/id/${i + 1}/400/300`
        }))
    };
  }
};
</script>

We just set the link prop to the URL we want. Then we can click on the slide to go to the URL.

Complex Slide Title and Content

We can populate the content slot to populate the content of the slides:

<template>
  <div id="app">
    <vueper-slides lazy lazy-load-on-drag>
      <vueper-slide v-for="i of 10" :key="i">
        <template v-slot:content>Complex content {{i}}</template>
      </vueper-slide>
    </vueper-slides>
  </div>
</template>

<script>
import { VueperSlides, VueperSlide } from "vueperslides";
import "vueperslides/dist/vueperslides.css";

export default {
  name: "App",
  components: { VueperSlides, VueperSlide }
};
</script>

We can add anything we want into our slides.

Conclusion

Vueper Slides is a very useful Vue carousel library that has many customization options.

Categories
Vue

Add Slides to a Vue App with the Vueper Slides Library

With the Vueper Slides library, we can add a carousel to our Vue app easily.

In this article, we’ll look at how to use it to add a carousel to our Vue app.

Installation

We can install the vueperslides package by running:

npm i --S vueperslides

Also, we can include the script tag and CSS for the library:

<head>
  //...
  <script src="https://unpkg.com/vue"></script>
  <script src="https://unpkg.com/vueperslides"></script>
  <link href="https://unpkg.com/vueperslides/dist/vueperslides.css" rel="stylesheet">
</head>

Add a Carousel

Once we installed the package, we can add a carousel by writing:

<template>
  <div id="app">
    <vueper-slides>
      <vueper-slide
        v-for="i of 10"
        :key="i"
        :title="`title ${i.toString()}`"
        :content="`slide ${i.toString()}`"
      />
    </vueper-slides>
  </div>
</template>

<script>
import { VueperSlides, VueperSlide } from "vueperslides";
import "vueperslides/dist/vueperslides.css";

export default {
  name: "App",
  components: { VueperSlides, VueperSlide }
};
</script>

We import the packages and the CSS to add the slider.

The vueper-slides component is the carousel container.

vueper-slide has the slides.

The title prop has the slide title.

content has the slide content.

We can also make the slides autoplay with the autoplay prop:

<template>
  <div id="app">
    <vueper-slides autoplay>
      <vueper-slide
        v-for="i of 10"
        :key="i"
        :title="`title ${i.toString()}`"
        :content="`slide ${i.toString()}`"
      />
      <template v-slot:pause>pause</template>
    </vueper-slides>
  </div>
</template>

<script>
import { VueperSlides, VueperSlide } from "vueperslides";
import "vueperslides/dist/vueperslides.css";

export default {
  name: "App",
  components: { VueperSlides, VueperSlide }
};
</script>

We populate the pause slot to add a pause button.

Also, we can add the style prop to add the styles.

For example, we can write:

<template>
  <div id="app">
    <vueper-slides autoplay>
      <vueper-slide
        v-for="i of 10"
        :key="i"
        :title="`title ${i.toString()}`"
        :content="`slide ${i.toString()}`"
        :style="`background-color: ${colors[i % colors.length]}`"
      />
    </vueper-slides>
  </div>
</template>

<script>
import { VueperSlides, VueperSlide } from "vueperslides";
import "vueperslides/dist/vueperslides.css";

export default {
  name: "App",
  components: { VueperSlides, VueperSlide },
  data() {
    return {
      colors: ["red", "green", "blue"]
    };
  }
};
</script>

We can set the background color of the slides with the style prop.

Custom Arrows and Bullets

We can change the colors of the bullet with our own styles.

For example, we can write:

<template>
  <div id="app">
    <vueper-slides>
      <vueper-slide
        v-for="i of 10"
        :key="i"
        :title="`title ${i.toString()}`"
        :content="`slide ${i.toString()}`"
      />
    </vueper-slides>
  </div>
</template>

<script>
import { VueperSlides, VueperSlide } from "vueperslides";
import "vueperslides/dist/vueperslides.css";

export default {
  name: "App",
  components: { VueperSlides, VueperSlide }
};
</script>

<style>
.vueperslides__bullet .default {
  background-color: rgba(0, 0, 0, 0.3);
  border: none;
  box-shadow: none;
  transition: 0.3s;
  width: 16px;
  height: 16px;
}

.vueperslides__bullet--active .default {
  background-color: #42b983;
}

.vueperslides__bullet span {
  display: block;
  color: #fff;
  font-size: 10px;
  opacity: 0.8;
}
</style>

to set the bullet styles by setting the .vueperslides__bullet span class.

We can also populate the bullet slot with our own bullet:

<template>
  <div id="app">
    <vueper-slides>
      <vueper-slide
        v-for="i of 10"
        :key="i"
        :title="`title ${i.toString()}`"
        :content="`slide ${i.toString()}`"
      />
      <template v-slot:bullet="{ active, slideIndex, index }">{{ active ? '&ofcir;' : '&olcir;' }}</template>
    </vueper-slides>
  </div>
</template>

<script>
import { VueperSlides, VueperSlide } from "vueperslides";
import "vueperslides/dist/vueperslides.css";

export default {
  name: "App",
  components: { VueperSlides, VueperSlide }
};
</script>

active indicates whether the slide is active or not.

slideIndex has the slide index.

Conclusion

The Vueper Slides library lets us add slides to a Vue app easily.

Categories
Vue

Add a Slider to a Vue App with the vue-owl-carousel Library

With the vue-owl-carousel library, we can add a carousel to our Vue app easily.

In this article, we’ll look at how to use it to add a carousel to our Vue app.

Installation

We can install the vue-owl-carousel library by running:

npm i vue-owl-carousel

Usage

Once we installed it, then we can use it by writing:

<template>
  <div id="app">
    <carousel>
      <img v-for="n of 10" :key="n" :src="`https://placeimg.com/200/200/any?${n}`">
    </carousel>
  </div>
</template>

<script>
import carousel from "vue-owl-carousel";

export default {
  name: "App",
  components: { carousel }
};
</script>

We import the component and then populate the carousel with images.

The carousel component is the carousel container.

It comes with navigation buttons and styles built-in.

Options

Various options are available as props.

items is the number of items we want to see on the screen. It defaults to 3.

margin is the margin-right of an item. It’s a number.

loop lets us set whether to loop through the items when we reach the end.

center sets whether to center our items. It’s a boolean value.

nav sets whether we want to show the navigation buttons. It’s a boolean value.

autoplay sets whether we want to make the carousel run automatically. It’s a boolean value.

autoplaySpeed sets the speed for autoplay. It’s a number.

rewind sets whether we want to go backward. It’s a boolean value.

mouseDrag sets whether we enable dragging slides with a mouse. It’s a boolean value.

touchDrag sets whether we enable dragging slides with touch. It’s a boolean value.

pullDrag sets whether we enable pulling slides. It’s a boolean value.

autoWidth and autoHeight lets us set whether to automatically size the carousel.

autoplayTimeout lets us set the autoplay interval. It’s a number.

autoplayHoverPause lets us pause on mouse hover. It’s a boolean value.

responsive lets us set the option for each slide. It’s an object.

For example, we can write:

<template>
  <div id="app">
    <carousel :responsive="responsive">
      <img v-for="n of 10" :key="n" :src="`https://placeimg.com/200/200/any?${n}`">
    </carousel>
  </div>
</template>

<script>
import carousel from "vue-owl-carousel";

export default {
  name: "App",
  components: { carousel },
  data() {
    return {
      responsive: { 0: { items: 1, nav: false }, 600: { items: 3, nav: true } }
    };
  }
};
</script>

The keys are the breakpoints and the values are objects that set how many items to show and whether to show the navigation controls.

Events

The carousel component emits the following events:

  • initialize
  • initialized
  • resize
  • resized
  • refresh
  • refreshed
  • update
  • updated
  • drag
  • dragged
  • translate
  • translated
  • to
  • changed

This document shows when they’re triggered.

Conclusion

The vue-owl-carousel library is an easy to use slider library for Vue apps based on Own Carousel.

Categories
Vue

Add a Slider to a Vue App with the vue-agile Library

With the vue-agile library, we can add a carousel to our Vue app easily.

In this article, we’ll look at how to use it to add a carousel to our Vue app.

Installation

We can install it by running:

yarn add vue-agile

or

npm install vue-agile

The library doesn’t come with any styles so we’ll have to add them ourselves.

We can optionally add the CSS into the head tag in public/index.html by writing:

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

Add a Carousel

Once we installed the package, we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueAgile from "vue-agile";

Vue.use(VueAgile);
Vue.config.productionTip = false;

new Vue({
  render: (h) => h(App)
}).$mount("#app");

App.vue

<template>
  <div id="app">
    <agile>
      <div class="slide" v-for="n of 10" :key="n">
        <h3>slide {{n}}</h3>
      </div>
    </agile>
  </div>
</template>

<script>
export default {
  name: "App"
};
</script>

We register the plugin in main.js .

Then we can use it in any component.

The agile component has the carousel container.

The divs are the slides.

Now we should see the slides with the navigation buttons at the bottom.

Responsive Slider

We can add many options in our slide, including adding breakpoints to make it responsive.

For example, we can write:

<template>
  <div id="app">
    <agile :options="options">
      <div class="slide" v-for="n of 10" :key="n">
        <h3>slide {{n}}</h3>
      </div>
    </agile>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      options: {
        navButtons: false,
        responsive: [
          {
            breakpoint: 600,
            settings: {
              dots: false
            }
          },
          {
            breakpoint: 900,
            settings: {
              navButtons: true,
              dots: true,
              infinite: false
            }
          }
        ]
      }
    };
  }
};
</script>

We have the options reactive property with the responsive property.

The breakpoint has the breakpoints that lets us decide what to show with a given breakpoint.

navButtons indicates whether we show the nav buttons or not.

dots lets us show the dots or not.

infinite indicates whether we want to loop through the items forever.

Custom Arrows and Nav Buttons

We can populate the prevButton and nexButton slots to add the buttons for going to the previous and next slides.

For example, we can write:

<template>
  <div id="app">
    <agile>
      <div class="slide" v-for="n of 10" :key="n">
        <h3>slide {{n}}</h3>
      </div>
      <template slot="prevButton">prev</template>
      <template slot="nextButton">next</template>
    </agile>
  </div>
</template>

<script>
export default {
  name: "App"
};
</script>

The content will be located inside the button as their content.

Caption

Also, we can populate the caption slot to add our own captions.

For example, we can write:

<template>
  <div id="app">
    <agile @after-change="e => currentSlide = e.currentSlide">
      <div class="slide" v-for="n of 10" :key="n">
        <h3>slide {{n}}</h3>
      </div>
      <template slot="caption">caption {{ currentSlide }}</template>
    </agile>
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      currentSlide: 0
    };
  }
};
</script>

We listen to the after-change event emitted by agile to get the current slide with the currentSlide property.

Then we can populate the caption with it to show the current slide index in the caption.

Conclusion

The vue-agile library is a flexible and easy to use carousel library for Vue apps.

Categories
Vue

Add a Timeline to a Vue App

We can add a timeline to a Vue app with premade components.

In this article, we’ll look at how to add a timeline with these components.

Vue Horizontal Timeline

The Vue Horizontal Timeline package is an easy to use package to let us add an outline to our Vue app.

To install it, we run:

npm i vue-horizontal-timeline

Then we can use it by writing:

main.js

import Vue from "vue";
import App from "./App.vue";
import VueHorizontalTimeline from "vue-horizontal-timeline";

Vue.use(VueHorizontalTimeline);
Vue.config.productionTip = false;

new Vue({
  render: (h) => h(App)
}).$mount("#app");

App.vue

<template>
  <vue-horizontal-timeline :items="items"/>
</template>

<script>
export default {
  data() {
    const example1 = {
      title: "Title example 1",
      content: "Lorem ipsum dolor sit amet."
    };
    const example2 = {
      title: "Title example 2",
      content: "Lorem ipsum dolor sit amet."
    };
    const example3 = {
      title: "Title example 3",
      content: "Lorem ipsum dolor sit amet."
    };
    const items = [example1, example2, example3];

    return { items };
  }
};
</script>

We register the VueHorizontalTimeline in main.js .

Then in App.vue , we add the vue-horizontal-timeline component to add the timeline.

The items prop has the items. Each entry has the title and content properties to display the title and content.

items-selected has the object that’s set when it’s clicked.

item-unique-key has the key.

title-attr has the property name of the title.

title-centered lets us set whether to center the title.

title-substr lets us set the subtitle for the title.

We can replace title with content and set the content.

min-width has the min-width of the timeline.

min-height has the min-height of the timeline.

timeline-padding has the timeline padding.

timeline-background has the background of the timeline.

line-color has the timeline line’s color.

clickable makes the card clickable that returns the object.

vue-cute-timeline

Another library to add a timeline to a Vue app is the vue-cute-timeline library.

To install it, we run:

yarn add vue-cute-timeline --save

Then we can use it by using the timeline , timeline-title and timeline-item components.

For example, we can write:

<template>
  <timeline>
    <timeline-title>title</timeline-title>
    <timeline-item bg-color="#9dd8e0">item1</timeline-item>
    <timeline-item :hollow="true">item2</timeline-item>
  </timeline>
</template>

<script>
import { Timeline, TimelineItem, TimelineTitle } from "vue-cute-timeline";

export default {
  components: {
    Timeline,
    TimelineItem,
    TimelineTitle
  }
};
</script>

We set the bg-color to set the background color of the dot.

hollow makes the dot hollow.

We’ll see the vertical timeline.

The others slot of timeline-item can be used to replace the circle with our own image.

For example, we can write:

<template>
  <timeline>
    <timeline-title>title</timeline-title>
    <timeline-item bg-color="#9dd8e0">
      <img
        src="https://i.picsum.photos/id/23/10/10.jpg?hmac=vbsZXumVCKRVT_EpOvXvctEtIRS_NFCzkmygpuP_QDk"
        slot="others"
      >
      item1
    </timeline-item>
    <timeline-item :hollow="true">item2</timeline-item>
  </timeline>
</template>

<script>
import { Timeline, TimelineItem, TimelineTitle } from "vue-cute-timeline";

export default {
  components: {
    Timeline,
    TimelineItem,
    TimelineTitle
  }
};
</script>

to add the image inside the dot.

Conclusion

We can add the Vue Horizontal Timeline or vue-cute-timeline package to add timelines to a Vue app.