1+ import { trigger , state , animate , transition , style } from '@angular/animations' ;
2+
3+ export function fadeIn ( ) {
4+ return trigger ( 'fadeIn' , [
5+ // route 'enter' transition
6+ transition ( ':enter' , [
7+
8+ // styles at start of transition
9+ style ( { opacity : 0 } ) ,
10+
11+ // animation and styles at end of transition
12+ animate ( '.3s' , style ( { opacity : 1 } ) )
13+ ] ) ,
14+ ] ) ;
15+ }
16+
17+ export function slideInOut ( ) {
18+ return trigger ( 'slideInOut' , [
19+
20+ // end state styles for route container (host)
21+ state ( '*' , style ( {
22+ // the view covers the whole screen with a semi tranparent background
23+ position : 'fixed' ,
24+ top : 0 ,
25+ left : 0 ,
26+ right : 0 ,
27+ bottom : 0 ,
28+ backgroundColor : 'rgba(0, 0, 0, 0.8)'
29+ } ) ) ,
30+
31+ // route 'enter' transition
32+ transition ( ':enter' , [
33+
34+ // styles at start of transition
35+ style ( {
36+ // start with the content positioned off the right of the screen,
37+ // -400% is required instead of -100% because the negative position adds to the width of the element
38+ right : '-400%' ,
39+
40+ // start with background opacity set to 0 (invisible)
41+ backgroundColor : 'rgba(0, 0, 0, 0)'
42+ } ) ,
43+
44+ // animation and styles at end of transition
45+ animate ( '.5s ease-in-out' , style ( {
46+ // transition the right position to 0 which slides the content into view
47+ right : 0 ,
48+
49+ // transition the background opacity to 0.8 to fade it in
50+ backgroundColor : 'rgba(0, 0, 0, 0.8)'
51+ } ) )
52+ ] ) ,
53+
54+ // route 'leave' transition
55+ transition ( ':leave' , [
56+ // animation and styles at end of transition
57+ animate ( '.5s ease-in-out' , style ( {
58+ // transition the right position to -400% which slides the content out of view
59+ right : '-400%' ,
60+
61+ // transition the background opacity to 0 to fade it out
62+ backgroundColor : 'rgba(0, 0, 0, 0)'
63+ } ) )
64+ ] )
65+ ] )
66+ }
0 commit comments