250x250
Notice
Recent Posts
Recent Comments
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

진스

vue 에서 슬라이더 사용하기 (vue-carousel2) 본문

Vue

vue 에서 슬라이더 사용하기 (vue-carousel2)

입방정 2021. 4. 26. 16:00
728x90

vue-carousel2 vs vue-slick vs vue-swiper 뭘 사용하지?

 

www.npmtrends.com/vue-carousel-vs-vue-slick-vs-vue-swiper

 

vue carousel vs vue slick vs vue swiper | npm trends

Compare npm package download statistics over time: vue carousel vs vue slick vs vue swiper

www.npmtrends.com

 

그렇다면 vue-carousel 사용법은?

 

vue-owl-carousel

 

vue-owl-carousel

VueJS wrapper for Owl Carousel

www.npmjs.com

  • :autoplay : 일정 시간마다 자동 스크롤
  • :nav : 좌우 클릭시 스크롤 되는 버튼을 숨기거나 노출합니다.
  • :dots : 컨텐츠 하단에 컨텐츠의 인덱스를 표현합니다.

 

방법1. ( 간단히 data만 지정)

npm i -s vue-owl-carousel2

<template>

  <div class="test-wrap">

    <div class="carousel-wrap">

      <carousel v-bind="options" @initialized="init" @changed="changed">

        <img src="@/assets/03.jpg" />

        <img src="@/assets/03.jpg" />

        <img src="@/assets/03.jpg" />

        <img src="@/assets/03.jpg" />

      </carousel>

    </div>

  </div>

</template>

 

<script>

import carousel from "vue-owl-carousel2";

 

export default {

  name: "swipeTest",

  components: {

    carousel,

  },

  data() {

    return {

      plugin: null,

      options: {

        autoplay: false,

        items: 1,

        startPosition: 2,

        autoplayTimeout: 1000,

      },

    };

  },

};

</script>

 

<style scoped>

.test-wrap {

  border1px solid #000;

  height3000px;

}

.carousel-wrap {

  width300px;

  margin0 auto;

}

</style>

 

 

방법2.

npm i -s vue-owl-carousel2

<template>

  <div class="test-wrap">

    <div class="carousel-wrap">

      <carousel v-bind="options" @initialized="init" @changed="changed">

        <img src="@/assets/03.jpg" />

        <img src="@/assets/04.jpg" />

        <img src="@/assets/05.jpg" />

      </carousel>

    </div>

  </div>

</template>

 

<script>

import carousel from "vue-owl-carousel2";

 

export default {

  name: "swipeTest",

  components: {

    carousel,

  },

  data() {

    return {

      plugin: null,

      options: {

        autoplay: false,

        items: 1,

        startPosition: 2,

        autoplayTimeout: 1000,

      },

    };

  },

  methods: {

    handleScroll() {

      window.addEventListener("scroll"() => {

        let scrollT = window.scrollY;

 

        if (scrollT > 0 && this.options.autoplay === false) {

          this.options.autoplay = true;

          setTimeout(() => {

            this.plugin.refresh();

          }, 300);

        } else if (scrollT === 0) {

          this.options.autoplay = false;

          setTimeout(() => {

            this.plugin.refresh();

          }, 300);

        }

      });

    },

    init() {

      this.plugin = this.$children[0];

    },

    changed(e) {

      this.options.startPosition = e.item.index;

    },

  },

  mounted() {

    this.handleScroll();

  },

  destroyed() {

    window.removeEventListener("scroll"this.handleScroll);

  },

};

</script>

 

<style scoped>

.test-wrap {

  border1px solid #000;

  height3000px;

}

.carousel-wrap {

  width300px;

  margin0 auto;

}

</style>

 

 

728x90
Comments