Carousel走马灯
走马灯,轮播图
代码演示
最简单的用法。
import { Component } from '@angular/core';
@Component({
selector: 'demo-carousel-basic',
template: `
<WingBlank>
<Carousel [infinite]="true"
[vertical]="false"
[selectedIndex]="1"
(beforeChange)="beforeChange($event)"
(afterChange)="afterChange($event)"
>
<CarouselSlide *ngFor="let item of state.data">
<div style="display: inline-block; width: 100%;" [ngStyle]="{'height': state.imgHeight}">
<img src="https://zos.alipayobjects.com/rmsportal/{{item}}.png" style=" pointer-events: none; width: 100%;"/>
</div>
</CarouselSlide>
</Carousel>
</WingBlank>
`
})
export class DemoCarouselBasicComponent {
state = {
data: ['AiyWuByWklrrUDlFignR', 'TekJlZRVCjLFexlOCuWn', 'IJOtIlfsYdTyaDTRVrLI'],
imgHeight: '184px'
};
beforeChange(event) {
console.log('slide ' + event.from + ' to ' + event.to);
}
afterChange(event) {
console.log('slide to ' + event);
}
}
子元素数量变化。
import { Component } from '@angular/core';
@Component({
selector: 'demo-carousel-basic-dynamic',
template: `
<WingBlank>
<div Button (onClick)="onClick1()">Click me to add child</div>
<WhiteSpace></WhiteSpace>
<Carousel [infinite]="true"
(beforeChange)="beforeChange($event)"
(afterChange)="afterChange($event)"
>
<CarouselSlide *ngFor="let item of state.data;let i = index" [ngStyle]="{'height': state.imgHeight}">
<div style="display: inline-block; width: 100%;" [ngStyle]="{'height': state.imgHeight}">
<img src="https://zos.alipayobjects.com/rmsportal/{{item}}.png" style="pointer-events: none; width: 100%;"/>
</div>
</CarouselSlide>
</Carousel>
</WingBlank>
`
})
export class DemoCarouselBasicDynamicComponent {
state = {
data: ['AiyWuByWklrrUDlFignR', 'TekJlZRVCjLFexlOCuWn', 'IJOtIlfsYdTyaDTRVrLI'],
imgHeight: '184px'
};
beforeChange(event) {
console.log('slide ' + event.from + ' to ' + event.to);
}
afterChange(event) {
console.log('slide to ' + event);
}
onClick1() {
this.state.data.push('AiyWuByWklrrUDlFignR');
}
}
import { Component } from '@angular/core';
@Component({
selector: 'demo-carousel-vertical',
template: `
<WingBlank>
<WhiteSpace></WhiteSpace>
<Carousel class="my-carousel"
[autoplay]="true"
[infinite]="true"
[vertical]="true"
[dots]="false"
[dragging]="false"
>
<CarouselSlide *ngFor="let item of state.data">
<div class="v-item">carousel {{item}}</div>
</CarouselSlide>
</Carousel>
</WingBlank>
`,
styles: [
`
.my-carousel .v-item {
height: 36px;
line-height: 36px;
padding-left: 10px;
}
`
]
})
export class DemoCarouselVerticalComponent {
state = {
data: ['1', '2', '3']
};
}
import { Component } from '@angular/core';
@Component({
selector: 'demo-carousel-lottery',
template: `
<WingBlank>
<WhiteSpace></WhiteSpace>
<Carousel class="my-carousel"
[dots]="false"
[speed]="200"
[autoplay]="true"
[infinite]="true"
[vertical]="true"
[dragging]="false"
[autoplayInterval]="300"
>
<CarouselSlide *ngFor="let item of state.data;let i = index">
<div class="v-item">carousel {{item}}</div>
</CarouselSlide>
</Carousel>
</WingBlank>
`,
styles: [
`
.my-carousel .v-item {
height: 36px;
line-height: 36px;
padding-left: 10px;
}
`
]
})
export class DemoCarouselLotteryComponent {
state = {
data: ['ring', 'ruby', 'iPhone', 'iPod', 'sorry', 'tourism', 'coke', 'ticket', 'note']
};
}
API
属性 | 说明 | 类型 | 默认值 |
---|---|---|---|
selectedIndex | 手动设置当前显示的索引 | number | 0 |
dots | 是否显示面板指示点 | Boolean | true |
vertical | 垂直显示 | Boolean | false |
autoplay | 是否自动切换 | Boolean | false |
autoplayInterval | 自动切换的时间间隔 | Number | 3000 |
infinite | 是否循环播放 | Boolean | false |
afterChange | 切换面板后的回调函数 | (current: number): void | 无 |
dotStyle | 指示点样式 | Object | 无 |
dotActiveStyle | 当前激活的指示点样式 | Object | 无 |
swipeSpeed | 滑动灵敏度 | number | 12 |
dragging | 是否允许滑动切换 | Boolean | (子元素大于1时为true, 否则为false) |
当前内容版权归 ant.design 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 ant.design .