@@ -56,3 +56,58 @@ export const mdTransitionAnimation = (_: HTMLElement, opts: TransitionOptions):
5656
5757 return rootTransition ;
5858} ;
59+
60+
61+ const dpToPx = ( n : number ) => window . devicePixelRatio * n ;
62+
63+ export const mdTransitionAnimation2 = ( _ : HTMLElement , opts : TransitionOptions ) : Animation => {
64+ const enteringEl = opts . enteringEl ;
65+ const leavingEl = opts . leavingEl ;
66+
67+ // choose from/to transforms depending on navigation direction
68+ let enterFrom : string , enterTo : string , leaveFrom : string , leaveTo : string ;
69+ if ( opts . direction === 'forward' ) {
70+ enterFrom = `translateX(${ dpToPx ( 30 ) } px)` ;
71+ enterTo = 'translateX(0%)' ;
72+ leaveFrom = 'translateX(0%)' ;
73+ leaveTo = `translateX(-${ dpToPx ( 30 ) } px)` ;
74+ } else {
75+ enterFrom = `translateX(-${ dpToPx ( 30 ) } px)` ;
76+ enterTo = 'translateX(0%)' ;
77+ leaveFrom = 'translateX(0%)' ;
78+ leaveTo = `translateX(${ dpToPx ( 30 ) } px)` ;
79+ }
80+
81+ const rootAninmation = createAnimation ( ) ;
82+
83+ const enterFade = createAnimation ( )
84+ . addElement ( enteringEl )
85+ . delay ( 100 )
86+ . duration ( 200 )
87+ . easing ( 'cubic-bezier(0.0, 0.0, 0.2, 1.0)' )
88+ . fromTo ( 'opacity' , '0' , '1' ) ;
89+ const enterSlide = createAnimation ( )
90+ . addElement ( enteringEl )
91+ . duration ( 300 )
92+ . easing ( 'cubic-bezier(0.4, 0.0, 0.2, 1.0)' )
93+ . fromTo ( 'transform' , enterFrom , enterTo ) ;
94+
95+ rootAninmation . addAnimation ( [ enterFade , enterSlide ] ) ;
96+
97+ if ( leavingEl ) {
98+ const exitFade = createAnimation ( )
99+ . addElement ( leavingEl )
100+ . duration ( 100 )
101+ . easing ( 'cubic-bezier(0.4, 0.0, 1.0, 1.0)' )
102+ . fromTo ( 'opacity' , '1' , '0' ) ;
103+ const exitSlide = createAnimation ( )
104+ . duration ( 300 )
105+ . addElement ( leavingEl )
106+ . easing ( 'cubic-bezier(0.4, 0.0, 0.2, 1.0)' )
107+ . fromTo ( 'transform' , leaveFrom , leaveTo ) ;
108+
109+ rootAninmation . addAnimation ( [ exitFade , exitSlide ] ) ;
110+ }
111+
112+ return rootAninmation ;
113+ }
0 commit comments