【问题标题】:Angular browseranimation slideup from bottomAngular 浏览器动画从底部向上滑动
【发布时间】:2021-10-22 00:14:49
【问题描述】:

我正在尝试创建简单的动画。好的是它可以工作,但我想要的方向相反。 我想做的是从下到上打开div。并从上到下关闭div。

这是我的角度动画

animations: [
    trigger('inOutAnimation', [
      transition(':enter', [
        style({ height: 0, opacity: 0,}),
        animate('1s linear ', style({ height: 318, opacity: 1 })),
      ]),
      transition(':leave', [
        style({ height: 318, opacity: 1 }),
        animate('1s linear', style({ height: 0, opacity: 0 })),
      ]),
    ]),
  ],

我正在制作动画的 Div 具有绝对位置,而他的父级具有相对位置。 我可以做些什么来反转动画?我在互联网上尝试了一些东西,但似乎没有什么能像animation-direction: reverse;

【问题讨论】:

    标签: css angular animation types css-animations


    【解决方案1】:

    这种方法会更好。定义state,然后像这样进行转换:

     animations: [
    trigger('inOutAnimation', [
      state('inState', style({ bottom: 0, opacity: 1 })),
      state('outState', style({ bottom: -100px, opacity: 0})),
      transition('inactive => active', [
        outState
        animate('1s linear', inState),
      ]),
      transition('active => inactive', [
        inState
        animate('1s linear', outState),
      ]),
      
    ]),
    ]
    

    然后您的inOutAnimation 应该以编程方式将其值从active 更改为inactive。另外我建议你使用bottom css 而不是height

    【讨论】:

    • 太棒了!谢谢
    • 谢谢。我重写了你的意思可能是trigger('inOutAnimation', [ state('inState', style({ bottom: 0, opacity: 1 })), state('outState', style({ bottom: -318, opacity: 0 })), transition('inState => outState', [animate('1s linear')]), transition('outState => inState', [animate('1s linear')]), ]), ], }),因为我遇到了一些错误。它不完全是我想要的。我希望 div 从底部打开,就像它应该从 div 底部到 div 顶部一样。现在它在 div 下开始并上升。
    • 好的。您可以简单地使用 height 属性。让我知道它是否有效或向我解释更多。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    • 2014-04-10
    • 2017-10-12
    相关资源
    最近更新 更多