通常设置所有动画
在一个或多个文件中,例如:
动画.main.ts
export const formStateMainTrigger = trigger("scrollAnimationMain", [
state(
"show",
style({
opacity: 1,
transform: "translateX(0)"
})
),
state(
"hide",
style({
opacity: 0,
transform: "translateX(-100%)"
})
),
transition("show => hide", animate("700ms ease-out")),
transition("hide => show", animate("700ms ease-in"))
]);
export const formState2Trigger = trigger("scrollAnimationSecond", [
state(
"show",
style({
opacity: 1,
transform: "translateX(0)"
})
),
state(
"hide",
style({
opacity: 0,
transform: "translateX(100%)"
})
),
transition("show => hide", animate("700ms ease-out")),
transition("hide => show", animate("700ms ease-in"))
]);
你就不能像
import { formStateMainTrigger } from './animations.main';
animations: [formStateMainTrigger]
对于组件内部的方法,您可以执行以下操作:
export function checkScroll(el) {
const componentPosition = el.nativeElement.offsetTop;
const scrollPosition = window.pageYOffset;
if (scrollPosition + 700 >= componentPosition) {
return "show";
}
return "hide";
}