css - Angular 应用程序中的过渡动画在 EDGE 中不起作用

标签 css angular css-animations microsoft-edge

我有一个简单的动画,当应用程序通过路由器导航到不同的组件时使用。

export function routerNavigation() {
  return trigger('routerNavigation', [
    state('void', style({ position: 'fixed' })),
    state('*', style({ position: 'fixed' })),
    transition(':enter', [
      style({ transform: 'translateY(200%)' }),
      animate('0.5s ease-in-out', style({ transform: 'translateY(0%)' }))
    ]),
    transition(':leave', [
      style({ transform: 'translateX(0%)' }),
      animate('0.5s ease-in-out', style({ transform: 'translateX(150%)' }))
    ])
  ]);
}

并且动画被添加到组件中,如下所示:

@Component({
  selector: 'app-branch',
  templateUrl: './branch.component.html',
  styleUrls: ['./branch.component.scss'],
  animations: [routerNavigation()],
  host: { '[@routerNavigation]': '' }
})

我已经运行了:

npm install --save web-animations-js`

并且我已经取消注释 pollyfil.js 文件中的行:

import 'web-animations-js'; 

注意事项:

  1. 这是一款 Angular 7 应用,在 Chrome 中运行良好。
  2. 动画在 MS Edge 中不工作
  3. 组件永远不会添加到 DOM,但会执行 components.ts 文件中的服务

我觉得这与动画的 transform: 'translateY(200%)' 样式有关,但我不确定如何调试它。

谁能帮我弄清楚为什么我的动画在 MS Edge 中不起作用。

为什么这不是重复的问题

SO 上的所有其他类似问题都添加了 polyfill for web animations 作为解决方案。我已经这样做了,但它仍然不起作用。

提前致谢

最佳答案

请引用this article (它包含一些演示,我已经在angular 7和IE、Edge和Chrome浏览器上测试过,它们都运行良好),我建议你可以尝试使用以下代码来使用动画:

import {trigger, stagger, animate, style, group, query as q, transition, keyframes} from '@angular/animations';
const query = (s,a,o={optional:true})=>q(s,a,o);

export const branchTransition = trigger('branchTransition', [
  transition(':enter', [
    query('.block', style({ opacity: 0 })),
    query('.block', stagger(300, [
      style({ transform: 'translateY(100px)' }),
      animate('1s cubic-bezier(.75,-0.48,.26,1.52)', style({transform: 'translateY(0px)', opacity: 1})),
    ])),
  ]),
  transition(':leave', [
    query('.block', stagger(300, [
      style({ transform: 'translateY(0px)', opacity: 1 }),
      animate('1s cubic-bezier(.75,-0.48,.26,1.52)', style({transform: 'translateY(100px)', opacity: 0})),
    ])),        
  ])
]);

@Component({
  selector: 'app-branch',
  templateUrl: './branch.component.html',
  styleUrls: ['./branch.component.css'],
  animations: [branchTransition],
  host: { '[@branchTransition]': '' }
})

另外,你也可以查看官方文档使用Route transition animations .

关于css - Angular 应用程序中的过渡动画在 EDGE 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54222647/

相关文章:

node.js - 寻找 Angular2 MEAN 堆栈

html - left 和 top 属性没有动画

html - 使元素下降并反弹而不超过其静态位置

jquery - 如何使设定的文本大小填充容器

jquery - 用ajax添加的按钮没有jQuery函数和CSS样式

css - 无法弄清楚为什么 CSS 仅导致我的一个页面在移动设备中显示不正确?

javascript - Angular Material Datepicker 切换图标单击事件

html - 为什么 align-self 属性在使用 flex 时不适用于导航栏?

javascript - 使用 webpack 的 Angular 2 测试 karma 找不到变量 : Map

jquery - CSS3 转换 : sending input to a transformed div