npm i gitart-scroll-carouselyarn add gitart-scroll-carouselFor better performance and optimization, we have several different CSS files that can be imported on demand. For base usage, you can import the following CSS files from dist:
// required styles for carousel and bottom scroll indicatorimport 'gitart-scroll-carousel/dist/index.css'// arrows styles if you want use default arrows..import 'gitart-scroll-carousel/dist/GSArrow.css'// styles of the layout you want to use. // read more in the layouts section.import 'gitart-scroll-carousel/dist/GSLayoutNumeric.css'If your project supports typescript and scss, remove /bundled from the import statement. css imports is not needed, you will use not bundled components.
import { GSCarousel, GSLayoutDefault,} from 'gitart-scroll-carousel'v1.2.0+
<script>import { GSCarousel, GSLayoutDefault } from 'gitart-scroll-carousel/bundled'import 'gitart-scroll-carousel/dist/index.css'import 'gitart-scroll-carousel/dist/GSArrow.css'import 'gitart-scroll-carousel/dist/GSLayoutNumeric.css'export default defineComponent({ components: { GSCarousel, }, setup() { return { items: [0, 1, 2, 3, 4], GSLayoutDefault, } },})</script><template> <GSCarousel :items="items" item-gap="16" :items-to-show="2" :layout="GSLayoutDefault" :layout-props="{ disableArrows: true, }" > <template #item="{ data }"> <div class="slide"> {{ data }} </div> </template> </GSCarousel></template><style scoped>.slide { box-shadow: 0 6px 15px -3px rgb(0 0 0/0.3); padding: 25px; border-radius: 5px; background: rgb(202, 202, 202); color: #000;}</style>With GSLayoutNumeric layout.
Detailed description of the layouts can be found in the layouts page.
Each carousel component should have a lyout. It's made to be easy to customize the carousel. Or even write you own layout.
Put the layout component in the layout prop.
Layout specific props you can put into layout-props (learn more about them in the layouts page).
<template> <GSCarousel :layout="GSLayoutDefault" :layout-props="{ disableArrows: true, }" > <!-- ... --> </GSCarousel></template>You can partially change appearance of the carousel by using css variables. Here is a list:
--gsc-custom-arrow-bg - background color of the arrow
--gsc-custom-arrow-bg-hover - background color of the arrow when hovered
--gsc-custom-arrow-color - color of the arrow
--gsc-custom-indicator-bar-color - color of the bar below the carousel
--gsc-custom-indicator-track-color - color of the track for bar
Overwrite styling by yourself. Just use some classes below. The package uses BEM. There is almost no inheritance.
Arrow:
.gsc-arrow, .gsc-arrow--side-right, .gsc-arrow--side-leftIndicator:
.gsc-indicator, .gsc-indicator--scrolling.gsc-indicator__track.gsc-indicator__barcurrentItemNumberupdate:current-item event that is emitted when the current item changes.v1.2.0+itemsArray#item slot.itemsToShowNumberkeyFieldStringnullitemGapNumber | String0previewSizeNumber120stickyNumber120ssrItemMinWidthNumber, StringnullssrItemMaxWidthNumber, StringnullMore control over the carousel you can find in the layouts page.
| Name | Description |
|---|---|
| item | slot for each carousel item |
item{ data: any // any data from the items array index: Number}data - current carousel item from items propsindex - index of the current carousel item.<GSCarousel :items="[1, 2, 3]" items-to-show="2"> <template #item="{ data, index }"> {{ data }} | {{ index }} </template></GSCarousel>