我刚刚创建了我的第一个Angular 项目,并试图使用Angular 动画来动画我的内容滚动(我希望内容在我滚动页面时出现),并添加一个令人震惊的动画.
由于某些原因,它不适合我,并考虑到角17是新的,并带来了许多变化,我找不到足够的资源来举例.
HTML文件组件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
@defer (on viewport;){
<div class="grid grid-items" [@staggerAnimation]="projects.length">
@for (project of projects; track project.id;) {
<div class="container">
<h4>{{project.name}}</h4>
<p>
{{project.description}}
</p>
<a class="explore-btn" href="{{project.link}}" target="_blank">Explore</a>
</div>
}
</div>
} @placeholder {
<div>Loading Projects...</div>
}
</body>
</html>
TS文件组件:
import { Component } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import 'zone.js';
import { provideAnimations } from '@angular/platform-browser/animations';
import {
trigger,
transition,
query,
stagger,
animate,
keyframes,
style,
} from '@angular/animations';
@Component({
selector: 'app-project-card',
standalone: true,
imports: [],
templateUrl: './project-card.component.html',
styleUrl: './project-card.component.css',
providers: [],
animations: [
trigger('staggerAnimation', [
transition('* => *', [
query(':enter', style({opacity: 0}), {optional: true}),
query(':enter', stagger('300ms', [
animate('1s ease-in', keyframes([
style({opacity: 0, transform: 'translateY(-75px)', offset: 0}),
style({opacity: 0.5, transform: 'translateY(35px)', offset: 0.3}),
style({opacity: 1, transform: 'translateY(0)', offset: 1}),
]))
]))
])
])
],
})
export class ProjectCardComponent {
projects = [ PROJECT OBJECTS HERE]
bootstrapApplication(ProjectCardComponent, {
providers: [provideAnimations()],
});
*我使用的是Angular 17的独立项目,因此不需要NgModule文件
I tried placing the trigger at the div with "container" and still didn't work.
I also tried removing the @defer which still lead to nothing.
不确定它是否相关,但此组件是子组件.