【问题标题】:Issue while applying fade in/fade out animation应用淡入/淡出动画时出现问题
【发布时间】:2020-07-04 14:54:28
【问题描述】:

我有一个带有几个按钮的页面;单击它们的动作会触发淡入/淡出动画。在该动画期间,div 的某些内容发生了变化。

一切正常,但是,在渐变动画开始之前,div 消失了大约半秒(而且看起来不太好)。我怎样才能防止它消失,只是变得不可见,然后再次可见(高度没有任何变化)?将高度设置为 100% 没有帮助。

CSS

.afterClick {
  -webkit-animation: fadeinout 0.6s linear forwards !important;
  animation: fadeinout 0.6s linear forwards !important;
}

@keyframes fadeinout {
  from {
    opacity: 1;
    animation-timing-function: ease;
  }
  50% {
    opacity: 0.5;
    animation-timing-function: ease-in;
  }
  to {
    opacity: 1;
    animation-timing-function: ease-in-out;
  }
}

HTML

<a href="#" class="some-class" (click)="setAnimation()">

<div class="afterClick" *ngIf="checkVisiblity == 'Y'">
some contents
</div>

TS

public checkVisiblity = 'Y';

setAnimation() {
  let context = this;
  context.checkVisiblity = 'N';
  setTimeout(function() {
    context.checkVisiblity = 'Y';
  }, 50);
}

【问题讨论】:

  • 请给我们一个堆栈闪电战代码的工作示例
  • 抱歉回复晚了。其实我已经解决了上面的问题。原因是在另一个 div 中,它包裹了页面并在里面有网格设置。看起来与这些设置有些冲突。

标签: css typescript animation


【解决方案1】:

尝试将animation-fill-mode 添加到 .afterClick 类

.afterClick {
  -webkit-animation: fadeinout 0.6s linear forwards !important;
  animation: fadeinout 0.6s linear forwards !important;
  animation-fill-mode: backwards;}

【讨论】:

  • 谢谢,试过了——可惜没有效果……
猜你喜欢
  • 2011-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-20
  • 2012-12-18
  • 2019-01-01
相关资源
最近更新 更多