Fuck.n router animation..

This commit is contained in:
mustafahlvc 2017-08-19 16:20:09 +03:00
parent b8d5c16237
commit d70ad0d3c7
2 changed files with 61 additions and 9 deletions

View File

@ -1,4 +1,6 @@
import { trigger, state, transition, animate, style } from '@angular/animations'; import { sequence, trigger, stagger, animate, style, group, query as q, transition, keyframes, animateChild, state } from '@angular/animations';
const query = (s, a, o = {optional: true}) => q(s, a, o);
export class Animations export class Animations
{ {
@ -55,7 +57,8 @@ export class Animations
]); ]);
public static slideInBottom = trigger('slideInBottom', [ public static slideInBottom = trigger('slideInBottom', [
state('void', style({ state('void',
style({
transform: 'translateY(100%)', transform: 'translateY(100%)',
display : 'none' display : 'none'
})), })),
@ -66,4 +69,43 @@ export class Animations
transition('void => *', animate('300ms')), transition('void => *', animate('300ms')),
transition('* => void', animate('300ms')) transition('* => void', animate('300ms'))
]); ]);
public static routerTransition = trigger('routerTransition', [
transition('* => *', [
query(':enter, :leave', style({
position: 'absolute',
height : '100vh'
})),
query(':enter', style({
transform: 'translateY(100%)',
opacity : 0
})),
sequence([
group([
query(':leave', [
style({
transform: 'translateY(0)',
opacity : 1
}),
animate('400ms cubic-bezier(0.250, 0.460, 0.450, 0.940)',
style({
transform: 'translateY(-100%)',
opacity : 0
}))
]),
query(':enter', [
style({transform: 'translateY(100%)'}),
animate('400ms cubic-bezier(0.250, 0.460, 0.450, 0.940)',
style({
transform: 'translateY(0%)',
opacity : 1
}))
])
]),
query(':leave', animateChild()),
query(':enter', animateChild())
])
])
]);
} }

View File

@ -1,20 +1,30 @@
import { Component, OnInit } from '@angular/core'; import { Component, HostBinding, OnInit } from '@angular/core';
import { PerfectScrollbarDirective } from 'ngx-perfect-scrollbar'; import { PerfectScrollbarDirective } from 'ngx-perfect-scrollbar';
import { NavigationEnd, Router } from '@angular/router'; import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { Animations } from '../../core/animations';
@Component({ @Component({
selector : 'fuse-content', selector : 'fuse-content',
templateUrl: './content.component.html', templateUrl: './content.component.html',
styleUrls : ['./content.component.scss'] styleUrls : ['./content.component.scss'],
animations : [Animations.routerTransition]
}) })
export class FuseContentComponent implements OnInit export class FuseContentComponent implements OnInit
{ {
@HostBinding('@routerTransition') routeAnimationState = false;
constructor( constructor(
private router: Router, private router: Router,
private activatedRoute: ActivatedRoute,
private perfectScrollbarDirective: PerfectScrollbarDirective private perfectScrollbarDirective: PerfectScrollbarDirective
) )
{ {
this.router.events
.filter((event) => event instanceof NavigationEnd)
.map(() => this.activatedRoute)
.subscribe((event) => {
this.routeAnimationState = !this.routeAnimationState;
});
} }
ngOnInit() ngOnInit()