Last active
May 25, 2018 10:41
-
-
Save perjansson/3a26dad8be5efbe42d94364f894b43ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
sequence, | |
trigger, | |
stagger, | |
animate, | |
style, | |
group, | |
query as q, | |
transition, | |
keyframes, | |
animateChild, | |
} from '@angular/animations' | |
const query = (style, animate, optional = { optional: true }) => | |
q(style, animate, optional) | |
const fade = [ | |
query(':enter, :leave', style({ position: 'fixed', width: '100%' })), | |
query(':enter', [style({ opacity: 0 })]), | |
group([ | |
query(':leave', [animate('0.3s ease-out', style({ opacity: 0 }))]), | |
query(':enter', [ | |
style({ opacity: 0 }), | |
animate('0.3s ease-out', style({ opacity: 1 })), | |
]), | |
]), | |
] | |
const fadeInFromDirection = direction => [ | |
query(':enter, :leave', style({ position: 'fixed', width: '100%' })), | |
group([ | |
query(':enter', [ | |
style({ | |
transform: `translateX(${direction === 'backward' ? '-' : ''}15%)`, | |
opacity: 0, | |
}), | |
animate( | |
'0.3s ease-out', | |
style({ transform: 'translateX(0%)', opacity: 1 }), | |
), | |
]), | |
query(':leave', [ | |
style({ transform: 'translateX(0%)' }), | |
animate('0.3s ease-out', style({ opacity: 0 })), | |
]), | |
]), | |
] | |
export const routerTransition = trigger('routerTransition', [ | |
transition('* => inital', fade), | |
transition('* => section', fade), | |
transition('* => forward', fadeInFromDirection('forward')), | |
transition('* => backward', fadeInFromDirection('backward')), | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment