<script setup lang="ts">
import { ref } from "vue";
type CarouselElement = {
link: string;
image: string;
label: string;
countryCode?: string;
};
interface Props {
carouselElements: CarouselElement[];
}
const props = withDefaults(defineProps<Props>(), {
carouselElements: () => [
{
link: "/",
image: "/assets/images/100.webp",
label: "Phenom 100",
},
{
link: "/",
image: "/assets/images/100.webp",
label: "Phenom 100",
},
{
link: "/",
image: "/assets/images/100.webp",
label: "Phenom 100",
},
],
});
const leftArrowRef = ref<HTMLButtonElement | null>(null);
const rightArrowRef = ref<HTMLButtonElement | null>(null);
const showArrows = ref(false);
const scrollableContainerRef = ref<HTMLDivElement | null>(null);
const scroll = (direction: "left" | "right") => {
if (scrollableContainerRef.value) {
const scrollAmount = 300;
if (direction === "left") {
scrollableContainerRef.value.scrollTo({
left: scrollableContainerRef.value.scrollLeft - scrollAmount,
behavior: "smooth",
});
} else {
scrollableContainerRef.value.scrollTo({
left: scrollableContainerRef.value.scrollLeft + scrollAmount,
behavior: "smooth",
});
}
}
};
</script>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter