gpt4 book ai didi

html - Angular 在单击按钮时为整个页面内容设置动画

转载 作者:太空宇宙 更新时间:2023-11-04 06:01:29 25 4
gpt4 key购买 nike

当我点击链接时,我想从底部开始动画。下面是我想要实现的图像。单击链接时,整个“红色”部分应该是动画的并且来自底部。为了实现这一目标,我所做的是:

Animate Content From Bottom Side

我试过的是:

@Component({
selector: 'mypage',
templateUrl: './mypage.component.html',
styleUrls: ['./mypage.component.scss'],
animations: [
trigger('slideInOut', [
state('flyIn', style({
transform: 'translateX(0)'
})),
transition(':enter', [
style({
transform: 'translateX(-100%)'
}),
animate('0.5s 300ms ease-in')
]),
transition(':leave', [
animate('0.3s ease-out', style({
transform: 'translateX(100%)'
}))
])
])
],
});

animationState = "flyIn";

dataRefresh(id) {
this.animationState = 'flyIn';
}
<div [@slideInOut]="animationState">
<!-- Here is other page content, which I need to animate from bottom -->
<div class="col-lg-10 col-md-10 col-10" (click)="dataRefresh(id)">
<div class="row">
<div class="col-lg-12 col-md-12 col-12">
<div class="branch_row_padding">
<div class="">Name</div>
<div class="">Description</div>
</div>
</div>
</div>
</div>
</div>

通过上面的尝试,只有链接 div 从左侧开始动画,我想为整个页面制作动画。

可能的解决方案是什么?

最佳答案

为什么不只用 CSS 来做呢?

相关css:

.myAnimateClass{
border:1px solid red;display:block; animation: example 3s ease-in-out;
}

@keyframes example {
from {margin-left:-100%;}
to {margin-left:0;}
}

相关TS:

import { Component } from '@angular/core';

@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
name = 'Angular 6';
show: boolean = true;
myAnimateClass: string = '';

resetClass() {
console.log("check");
setTimeout(() => {
this.myAnimateClass = 'myAnimateClass';
},100);
}

animatePage() {
if(this.myAnimateClass == 'myAnimateClass') {
this.myAnimateClass = 'something';
this.resetClass();
} else{
this.myAnimateClass = 'myAnimateClass';
}
}

}

相关HTML:

<div [ngClass]='myAnimateClass'>
<hello name="{{ name }}"></hello>
<p>
Start editing to see some magic happen :)
</p>

<button type="button" (click)='animatePage()'>Animation page</button>

<div >
<!-- Here is other page content, which I need to animate from bottom -->
<div class="col-lg-10 col-md-10 col-10" (click)="dataRefresh(id)">
<div class="row">
<div class="col-lg-12 col-md-12 col-12">
<div class="branch_row_padding">
<div class="">Name</div>
<div class="">Description</div>
</div>
</div>
</div>
</div>
</div>
</div>

检查 working stackblitz here

关于html - Angular 在单击按钮时为整个页面内容设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57247812/

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