【问题标题】:Change body styles from component via angular animation通过角度动画从组件更改身体样式
【发布时间】:2018-06-18 20:42:50
【问题描述】:

我有组件modal-window,我想用角度动画让它全屏。现在它被实现为document.querySelector('body').classList.toggle('modal-fullscreen');。同样在 css 中,我有 transition 0.3s 用于这个动画。现在我需要用角度动画重新制作它。如何直接从modal-window 组件动画更改body 的样式?

【问题讨论】:

    标签: css angular animation angular-animations


    【解决方案1】:

    您可以像这样使用ElementRef 来实现这一点 -

    constructor(private elRef: ElementRef) {
        console.log(elRef.nativeElement.ownerDocument.body);
      }
    

    你可以简单地使用

    document.body
    

    但是在服务端渲染的情况下不推荐使用document

    Working Example

    【讨论】:

      猜你喜欢
      • 2020-06-28
      • 1970-01-01
      • 2012-11-13
      • 2015-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多