gpt4 book ai didi

angular - 如何设计 ng-bootstrap Accordion ?

转载 作者:行者123 更新时间:2023-12-04 00:58:48 29 4
gpt4 key购买 nike

我想为 ng-bootstrap 的 Accordion 添加自定义淡入淡出样式!
我怎样才能实现它?

最佳答案

Following Solution is for ng-bootstrap version 5.x.x & 6.x.x & Angular 8 & 9



淡入淡出样式将不适用 如果 的内容 Accordion 从 DOM 中移除 , 所以, 你需要添加 [destroyOnHide]='false' 连同 ngb- Accordion 选择器。现在,当内容被隐藏时,内容不会从 DOM 中删除。

Accordion .component.html:
<div class="card">
<div class="card-body">

<!-- ngb Accordion starts -->

<ngb-accordion [destroyOnHide]='false' [closeOthers]="true" activeIds="panel1">

<ngb-panel id="panel1">
<ng-template ngbPanelTitle>
<span>Accordion Item 1 </span>
</ng-template>
<ng-template ngbPanelContent>
Donut caramels sweet roll bonbo
</ng-template>
</ngb-panel>

<ngb-panel id="panel2">
<ng-template ngbPanelTitle>
<span>Accordion Item 2 </span>
</ng-template>
<ng-template ngbPanelContent>
tootsie roll sweet gummi bears chocolate bar.
</ng-template>
</ngb-panel>

<ngb-panel id="panel3">
<ng-template ngbPanelTitle>
<span>Accordion Item 3 </span>
</ng-template>
<ng-template ngbPanelContent>
tootsie roll sweet gummi bears chocolate bar.
</ng-template>
</ngb-panel>

<ngb-panel id="panel4" [disabled]="true">
<ng-template ngbPanelTitle>
<span>Accordion Item 4 </span>
</ng-template>
<ng-template ngbPanelContent>
gummi bears jujubes cotton candy cake marshmallow. Tart cake danish dessert
</ng-template>
</ngb-panel>

</ngb-accordion>

<!-- ngb Accordion ends -->

</div>
</div>

Accordion .component.scss:
// collapse toggle
::ng-deep .collapse {
transition: max-height .55s, opacity .35s ease-in-out;
max-height: 0;
opacity: 0;
display: block !important;

&.show {
max-height: 100rem;
opacity: 1;
}
}

::ng-deep .accordion {
.card {
margin-bottom: 0 !important;
border-bottom: 1px solid rgba(0, 0, 0, .04) !important;

.card-header {
// padding-top: 0;
padding: 0;

button {
padding: 1.2rem;
width: 100%;

span {
float: left;
font-size: 1.2rem;
}
}
}

.card-body {
padding: 1rem;
}
}
}

您可以从 here. 看到现场演示

关于angular - 如何设计 ng-bootstrap Accordion ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60333365/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com