gpt4 book ai didi

angular - 切换标签时添加动画

转载 作者:行者123 更新时间:2023-12-03 00:33:36 24 4
gpt4 key购买 nike

我正在使用一些选项卡。有没有办法在切换标签时添加动画(向左/向右滑动)?

DEMO

代码

  viewMode = 'tab1';


<div class="container">
<div class="tab-slider--nav">
<ul class="tab-slider--tabs">
<li class="tab-slider--trigger" [class.active]="viewMode == 'tab1'" rel="tab1" (click)="viewMode ='tab1'">Tab 1</li>
<li class="tab-slider--trigger" [class.active]="viewMode == 'tab2'" rel="tab2" (click)="viewMode ='tab2'">Tab 2</li>
</ul>
</div>
<div class="tab-slider--container" [ngSwitch]="viewMode">
<div id="tab1" class="tab-slider--body" *ngSwitchCase="'tab1'">
<h2>First Tab</h2>
<p>Toggle switch style tab navigation. Currently only works with two tabs.</p>
<p>asdasd.</p>
</div>
<div id="tab2" class="tab-slider--body" *ngSwitchCase="'tab2'">
<h2>Second Tab</h2>
<p>asdad</p>
</div>
</div>
</div>

最佳答案

尝试使用 Angular 动画过渡和触发器,这是我的示例:

<body style="overflow:hidden">
<div class="container">
<div class="tab-slider--nav">
<ul class="tab-slider--tabs">
<li class="tab-slider--trigger" [class.active]="viewMode == 'tab1'" rel="tab1" (click)="viewMode ='tab1'">Tab 1</li>
<li class="tab-slider--trigger" [class.active]="viewMode == 'tab2'" rel="tab2" (click)="viewMode ='tab2'">Tab 2</li>
</ul>
</div>
<div class="tab-slider--container" [ngSwitch]="viewMode">
<div id="tab1" class="tab-slider--body" *ngSwitchCase="'tab1'" [@slideInOut]>
<h2>First Tab</h2>
<p>Toggle switch style tab navigation. Currently only works with two tabs.</p>
<p >Donec ullamcorper nulla non metus auctor fringilla. Donec ullamcorper nulla non metus auctor fringilla. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Nullam id dolor id nibh ultricies vehicula ut id elit. Nulla
vitae elit libero, a pharetra augue.</p>
</div>
<div id="tab2" class="tab-slider--body" *ngSwitchCase="'tab2'" [@slideInOut]>
<h2>Second Tab</h2>
<p>Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Cras mattis consectetur purus sit amet fermentum. Nulla vitae elit libero, a pharetra augue. Cras mattis consectetur purus sit amet fermentum. Aenean eu leo
quam. Pellentesque ornare sem lacinia quam venenatis vestibulum.</p>
</div>
</div>
</div>
</body>

TS:

@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
animations: [
trigger('slideInOut', [
transition(':enter', [
style({transform: 'translateX(+100%)'}),
animate('200ms ease-in', style({transform: 'translateX(0%)'}))
]),
]),
]
})

实例:https://stackblitz.com/edit/angular-dfaeek?file=src/app/app.module.ts

https://angular.io/guide/transition-and-triggers

另请检查一下:

https://material.angular.io/components/tabs/overview

关于angular - 切换标签时添加动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60487865/

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