Skip to content

Instantly share code, notes, and snippets.

@leochocolat
Created November 4, 2020 18:18
Show Gist options
  • Save leochocolat/1d9abe48806fecaeb7bb5efbaa8a0ad0 to your computer and use it in GitHub Desktop.
Save leochocolat/1d9abe48806fecaeb7bb5efbaa8a0ad0 to your computer and use it in GitHub Desktop.
<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