angular - 为 Angular 中的每个 mdb-carousel 项目添加间隔
问题描述
我想为 mdb-carousal 中的每个项目添加不同的间隔。我发现很少有解决方案,但它是基于 jQuery 的。我想要打字稿中的解决方案。
<div> <mdb-carousel [interval]="1000" [isControls]="false" class="carousel slide carousel-fade" [animation]="'fade'">
<mdb-carousel-item>
<!-- THIS NEEDS TO BE DISPLAYED FOR 5 SECS -->
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(68).jpg" alt="First slide">
</mdb-carousel-item>
<mdb-carousel-item>
<!-- THIS NEEDS TO BE DISPLAYED FOR 15 SECS -->
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(6).jpg" alt="Second slide">
</mdb-carousel-item>
解决方案
With little more research on the available carousel properties, I am able to solve the issue: Below is the solution.
In HTML, we need to pass the carousel component back to the Typescript using activeSlideChange method available for the slide event. Also need to add ids for each carousel item for reference
-- HTML
<div>
<mdb-carousel #carousal [interval]="1000" [isControls]="false" class="carousel slide carousel-fade" [animation]="'fade'"
(activeSlideChange)="activeSlideChange(carousal)" >
<mdb-carousel-item id='home'>
<!-- THIS NEEDS TO BE DISPLAYED FOR 5 SECS -->
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(68).jpg" alt="First slide">
</mdb-carousel-item>
<mdb-carousel-item id='time'>
<!-- THIS NEEDS TO BE DISPLAYED FOR 15 SECS -->
<img class="d-block w-100" src="https://mdbootstrap.com/img/Photos/Slides/img%20(6).jpg" alt="Second slide">
</mdb-carousel-item>
</mdb-carousel>
</div>
In typescript, we can define the activeSlideChange method like this
activeSlideChange(cc: CarouselComponent){
let slideItem = cc.slides[cc.activeSlide];
let id = slideItem.el.nativeElement.id;
console.log(id);
if ( id === 'home') {
cc.interval = 1000 * 5 ; // 5 secs
} else if ( id === 'time') {
cc.interval = 1000 * 15; // 15 secs
}else {
cc.interval = 5000;
}
}
推荐阅读
- visual-studio - 如何从我的桌面应用程序中删除开发控制台?
- convertigo - 在一页中加载多个视图
- angularjs - 绘制角度图表时不能清空 $scope.labels 和 $scope.data
- python - 在 Excel 工作簿中打开和修改特定工作表
- angular - Docker 和身份服务器 4、api、angular:无法分配请求的地址
- flutter - 如何在颤动 24 小时后删除 SharedPreferences?
- css - 用于响应式设计的 CSS 媒体查询
- php - 使用imagick创建多页pdf
- php - 设置安装 Sylius 的 Symfony 项目会出错
- javascript - Chrome 浏览器桌面通知