简体   繁体   English

Angular Universal SSR CSS 动画变换错误

[英]Angular Universal SSR CSS animation transform Error

I have added Angular universal to my app and followed the guide on https://angular.io/guide/universal It was realy simple, I'm just struggling with this Error:我已将 Angular 通用添加到我的应用程序并遵循https://angular.io/guide/universal上的指南这真的很简单,我只是在为这个错误而苦苦挣扎:

ERROR Error: Unable to build the animation due to the following errors: The provided animation property "transform" is not a supported CSS property for animations The provided animation property "transform" is not a supported CSS property for animations错误错误:由于以下错误,无法构建动画:提供的动画属性“transform”不是动画支持的 CSS 属性提供的动画属性“transform”不是动画支持的 CSS 属性

The reason for this is a simple Button with a keyframe animation which uses transform: rotate(0deg);这样做的原因是一个简单的 Button 带有关键帧动画,它使用了 transform:rotate(0deg); The button is round and rolls from the right to the left side after loading.按钮是圆形的,加载后从右侧滚动到左侧。

Is there any workaround to solve this issue?是否有解决此问题的解决方法? I'm sure that transform is quite a valid CSS property for animations.我确信转换对于动画来说是一个非常有效的 CSS 属性。

Edit : I use the transform Property inside of a components scss file.编辑:我在组件 scss 文件中使用 transform 属性。 The content is static and the component shows a whole site.内容是静态的,组件显示整个站点。 The css code is this: css代码是这样的:

  .roll-in {  animation: 2s linear 0s 1 animation;
    animation-fill-mode: both;
    }
@keyframes animation {
  0% {
    left: 110%;
  }

  10% {
    transform: rotate(0deg);
    left: 110%;
  }

  100% {
    transform: rotate(-720deg);
    left: 0px;
  }
}

After running the app with serve:ssr the element has no animation attribute.使用 serve:ssr 运行应用程序后,该元素没有动画属性。

I think, it happens when the animation starts on server side rendering itself.我认为,当动画在服务器端渲染本身时发生。 Since this is SSR , there is no meaning of loading the animations on server version.由于这是SSR ,因此在服务器版本上加载动画没有意义。

Load the animations only in Browser platform version.仅在Browser platform版本中加载动画。 So, animations will start only after the page rendered in browser view.因此,动画只会在浏览器视图中呈现页面后开始。 For example,例如,

component.ts组件.ts

import { Component, Inject } from '@angular/core';
import { PLATFORM_ID } from '@angular/core';
import { isPlatformBrowser } from '@angular/common';

@Component({
  selector: 'my-animated-component',
  templateUrl: './my-animated-component.html'
})
export class MyAnimatedComponent{
  isBrowser: boolean;

  constructor( @Inject(PLATFORM_ID) platformId: Object) {
    this.isBrowser = isPlatformBrowser(platformId);
  }
}

In markup在标记中

 <div *ngIf="isBrowser">
    <my-animated-component></my-animated-component>
 </div>

It's recommended to use Angular native animations rather than CSS animations.建议使用 Angular 原生动画而不是 CSS 动画。 A working example is here: https://stackblitz.com/edit/angular-animate-keyframes一个工作示例在这里: https : //stackblitz.com/edit/angular-animate-keyframes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM