【发布时间】:2019-09-14 01:33:28
【问题描述】:
我正在尝试为 Ngbcarousel 导航指示器(指示用户在哪张幻灯片上的圆点)设置动画,以便在用户单击(例如,第 5 个指示器)时它向右滚动,并继续向右滚动如果用户从第 6 个指示器开始点击直到它到达终点。
我已经将https://stackblitz.com/edit/ngu-carousel-ng6-7hxy9p?file=src/app/hello.component.ts 中的代码与 Ngbcarousel 组合在一起,这样导航就会显示为点。
基本上我得到了我想要的样子,但我不确定如何访问 Ngbcarousel dom 结构并将动画添加到有序列表(所以当我按下第 5 个点时,整个有序列表会移动向左,在右侧显示更多的点)
理想情况下,应该看起来像 Instagram 的轮播 -> https://codepen.io/swarad07/pen/xmzQKm
carousel.component.html
<ngb-carousel
#carousel
class="profile-detail-carousel"
[showNavigationArrows]="false"
[showNavigationIndicators]="true"
data-interval="false"
(click)="navigateCarousel($event)"
>
<ng-template ngbSlide *ngFor="let imageID of imageIDs">
<img class="carousel-img" [src]="profile | profileImage: imageID" />
</ng-template>
<ng-template ngbSlide *ngIf="!imageIDs?.length">
<img class="carousel-img" [src]="{} | profileImage" />
</ng-template>
</ngb-carousel>
caroursel.component.ts
navigateCarousel(event) {
// checks what slideNumber was clicked
const slideNumber = parseInt(event && event.path[0].id.match(/\d+/)[0], 10);
if (slideNumber >= 5) {
console.log(this.carousel); // carousel ol element to scroll right
}
}
carousel.component.scss
.profile-detail-carousel .carousel-indicators {
display: flex;
justify-content: left;
bottom: -40px !important;
overflow: hidden;
list-style-type: none;
text-align: center;
padding: 12px;
margin: 0;
width: 105px;
white-space: nowrap;
box-sizing: border-box;
margin: auto;
li {
display: inline-block;
border-radius: 50%;
border: 2px solid rgba(0, 0, 0, 0.55);
padding: 4px;
margin: 0 3px;
transition-timing-function: cubic-bezier(0.17, 0.67, 0.83, 0.67);
transition: 0.4s;
height: 1px;
width: 1px;
&.active {
background: #6b6b6b;
transform: scale(1.2);
}
}
}
感谢您的帮助,谢谢!
【问题讨论】:
标签: angular carousel ng-bootstrap