import Vue, { CreateElement, VNode } from "vue"; import { Component} from "vue-property-decorator"; import variables from "../../../lib/variables.json"; @Component class GalleryCarousel extends Vue { stopAnimation: boolean = false; mounted() { } public $refs: { carousel: HTMLElement }; nextSlide() { if (!this.stopAnimation) { this.stopAnimation = true; let corousel: HTMLElement = this.$refs.carousel; let corouselItems: NodeListOf = corousel.querySelectorAll(".rt-gallery-carousel-item"); let firstItem: HTMLElement = corouselItems[0]; let innerWidth: number = window.innerWidth; if (innerWidth <= parseInt(variables["mobile-upper-limit"])) { firstItem.style.marginLeft = "-47vw"; } else if (innerWidth <= parseInt(variables["tablet-upper-limit"])) { firstItem.style.marginLeft = "-20%"; } else { firstItem.style.marginLeft = "-12.5%"; } setTimeout(() => { firstItem.removeAttribute("style"); corousel.appendChild(firstItem); setTimeout(() => { this.stopAnimation = false; }, 10); }, 500); } } previousSlide() { if (!this.stopAnimation) { this.stopAnimation = true; let corousel: HTMLElement = this.$refs.carousel; let corouselItems: NodeListOf = corousel.querySelectorAll(".rt-gallery-carousel-item"); let lastItem: HTMLElement = corouselItems[corouselItems.length - 1]; let innerWidth: number = window.innerWidth; if (innerWidth <= parseInt(variables["mobile-upper-limit"])) { lastItem.style.marginLeft = "-47vw"; } else if (innerWidth <= parseInt(variables["tablet-upper-limit"])) { lastItem.style.marginLeft = "-20%"; } else { lastItem.style.marginLeft = "-12.5%"; } corousel.prepend(lastItem); setTimeout(() => { lastItem.removeAttribute("style"); },50) setTimeout(() => { setTimeout(() => { this.stopAnimation = false; }, 10); }, 500); } } render(h: CreateElement): VNode { return ; } } export default { component: GalleryCarousel, name: "RtGalleryCarousel" };