Run the CLI
Use the CLI to add the component to your project.
A slideshow component for cycling through elements with support for mouse drag, touch swipe, and automatic playback.
Use the CLI to add the component to your project.
Install the required dependencies for this component.
Create the component directory structure and add the following files to your project.
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { ZardCardComponent } from '../../card';
import { ZardCarouselImports } from '../carousel.imports';
@Component({
imports: [ZardCarouselImports, ZardCardComponent],
template: `
<div class="mx-auto w-3/4 max-w-md">
<z-carousel>
<z-carousel-content>
@for (slide of slides; track slide) {
<z-carousel-item>
<z-card>
<div class="flex h-25 items-center justify-center text-4xl font-semibold md:h-50">
{{ slide }}
</div>
</z-card>
</z-carousel-item>
}
</z-carousel-content>
</z-carousel>
</div>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ZardDemoCarouselDefaultComponent {
protected slides = ['1', '2', '3', '4', '5'];
}
To set the size of the items, you can use the basis utility class on the <z-carousel-item />.
To set the spacing between the items, we use a pl-[VALUE] utility on the <z-carousel-item /> and a negative -ml-[VALUE] on the <z-carousel-content />.
Content class: -ml-4
Item class: basis-1/3 pl-4
Current slide: 1 / 0
Scroll progress: 0%
Can scroll prev: No
Can scroll next: No
Slides in view:
Current slide: 1 / 0