这里是我制作的一段随机动画
import { trigger, animate, transition, style, keyframes} from '@angular/animations';
export const customAnimation=
trigger('customAnimation', [
transition(':leave', [
style({position: 'relative'}),
animate("250ms ease-in", keyframes([
style({top: 0}),
style({top: -300}),
]))
])
])
我随后将其导入到我的组件中。(animations: [customAnimation]
)
然而,我希望使用新的参数功能:
(http://sudheerjonna.com/blog/2017/06/30/angular-4-2-release-an-improved-version-for-animation-package/)。
例如,-300 将成为一个参数,并通过以下方式在我模板元素上调用它:
<div [@customAnimation]="{pixels: -300}">
由于我不想使用animation()
和useAnimation()
,因为我想在特定的dom元素上使用(也不使用query()
),所以我没能成功实现。
编辑:
已成功使用以下方法:
export const leavingTowardsTop=
trigger('leavingTowardsTop', [
transition(':leave', [
style({position: 'relative'}),
animate("250ms ease-in", keyframes([
style({top: 0}),
style({top: "{{pixels}}"})
]))
], {params : { pixels: "-30px" }})
])
唯一的问题是,我无法指定除默认值(-30)之外的其他值。我尝试过:
[@leavingTowardsTop]="{params : { pixels: '-300px' }}"
和
[@leavingTowardsTop]="{ pixels: '-300px' }"
我也尝试了不指定 '
或 px
,但它仍然占据 30 像素。