【问题标题】:angular - the animation effect fails when loading the componentangular - 加载组件时动画效果失败
【发布时间】:2020-05-13 01:19:26
【问题描述】:

我想在页面组件加载的时候做一个opacity的效果,但是我发现必须设置一个setTimeout()才能运行成功。 有没有更好的办法?

例如:

组件:

@Component({
  selector : 'my-app',
  template: `
  <div id="component" [ngClass]="{show: block}">
    content
  </div>
  `
})
export class FaderComponent implements OnInit {
  block: boolean = false
  constructor(){}
  ngOnInit() {

    setTimeout(()=>{
      this.block = true;
    },100)

  }
}

scss:

#component {
  opacity: 0;
  transition: 0.4s;
  &.show{
    opacity: 1;
  }
}

【问题讨论】:

标签: html angular typescript angular-animations


【解决方案1】:

您可以参考example 在组件加载时添加动画。

【讨论】:

    猜你喜欢
    • 2017-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多