Created
November 4, 2020 18:18
-
-
Save leochocolat/1d9abe48806fecaeb7bb5efbaa8a0ad0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="slider"> | |
<Slide v-for="(item, index) in items" v-bind:key="index" ref="slide" /> | |
</div> | |
</template> | |
<script> | |
import Slider from '@/components/Slide'; | |
export default { | |
data() { | |
return { | |
index: 0, | |
allowSlide: true, | |
}; | |
}, | |
components: { | |
Slider, | |
}, | |
methods: { | |
next() { | |
this.allowSlide = false; | |
const currentIndex = this.index; | |
const nextIndex = index + 1; | |
const timeline = new gsap.timeline({ onComplete: this.allowSlide }); | |
timeline.add(this.$refs.slide[index].transitionOut(), 0); | |
timeline.add(this.$refs.slide[nextIndex].transitionIn(), 0); | |
this.index = nextIndex; | |
}, | |
previous() { | |
this.allowSlide = false; | |
const currentIndex = this.index; | |
const nextIndex = index - 1; | |
const timeline = new gsap.timeline({ onComplete: this.allowSlide }); | |
timeline.add(this.$refs.slide[index].transitionOut(), 0); | |
timeline.add(this.$refs.slide[nextIndex].transitionIn(), 0); | |
}, | |
allowSlide() { | |
this.allowSlide = true; | |
}, | |
}, | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment