After researching CSS tutorials, I successfully changed the animation style from translateX
to margin-left
.
import {
animate,
group,
query,
style,
transition,
trigger,
} from '@angular/animations';
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import {
BrowserAnimationsModule,
provideAnimations,
} from '@angular/platform-browser/animations';
import 'zone.js';
@Component({
selector: 'app-root',
standalone: true,
template: `
<div class="container">
<div class="menu" *ngIf="showMenu" [@slideInOut]="showMenu">Menu</div>
<div class="content">Content<button (click)="toggleMenu()">Teste</button></div>
</div>
`,
animations: [
trigger('slideInOut', [
transition(':enter', [
style({ marginLeft: '-100%' }),
animate('200ms', style({ marginLeft: '0px' })),
]),
transition(':leave', [
animate('200ms', style({ marginLeft: '-100%' })),
]),
]),
],
imports: [CommonModule],
})
export class App {
name = 'Angular';
showMenu = true;
toggleMenu() {
this.showMenu = !this.showMenu;
}
}
bootstrapApplication(App, { providers: [provideAnimations()] });
stackblitz
References
- JSfiddle demo
- article