11export default {
22 name : 'QSlideTransition' ,
3+
34 props : {
45 appear : Boolean ,
56 duration : {
67 type : Number ,
78 default : 300
89 }
910 } ,
11+
1012 methods : {
11- __begin ( el , height ) {
13+ __begin ( el , height , done ) {
1214 el . style . overflowY = 'hidden'
1315 if ( height !== void 0 ) {
1416 el . style . height = `${ height } px`
1517 }
1618 el . style . transition = `height ${ this . duration } ms cubic-bezier(.25, .8, .50, 1)`
19+
20+ this . animating = true
21+ this . done = done
1722 } ,
23+
1824 __end ( el , event ) {
1925 el . style . overflowY = null
2026 el . style . height = null
2127 el . style . transition = null
2228 this . __cleanup ( )
2329 event !== this . lastEvent && this . $emit ( event )
2430 } ,
31+
2532 __cleanup ( ) {
33+ this . done && this . done ( )
34+ this . done = null
35+ this . animating = false
36+
2637 clearTimeout ( this . timer )
2738 this . el . removeEventListener ( 'transitionend' , this . animListener )
28- delete this . animListener
39+ this . animListener = null
2940 }
3041 } ,
42+
3143 beforeDestroy ( ) {
32- this . animListener && this . animListener ( )
44+ this . animating && this . __cleanup ( )
3345 } ,
46+
3447 render ( h ) {
3548 return h ( 'transition' , {
3649 props : {
@@ -42,46 +55,43 @@ export default {
4255 let pos = 0
4356 this . el = el
4457
45- if ( this . animListener ) {
46- pos = el . offsetHeight
47- this . animListener ( )
58+ if ( this . animating === true ) {
59+ this . __cleanup ( )
60+ pos = el . offsetHeight === el . scrollHeight ? 0 : void 0
4861 }
4962 else {
5063 this . lastEvent = 'hide'
5164 }
5265
53- this . __begin ( el , pos )
66+ this . __begin ( el , pos , done )
5467
55- this . animListener = ( ) => {
56- this . __end ( el , 'show' )
57- done ( )
58- }
5968 this . timer = setTimeout ( ( ) => {
6069 el . style . height = `${ el . scrollHeight } px`
70+ this . animListener = ( ) => {
71+ this . __end ( el , 'show' )
72+ }
6173 el . addEventListener ( 'transitionend' , this . animListener )
6274 } , 100 )
6375 } ,
6476 leave : ( el , done ) => {
6577 let pos
6678 this . el = el
6779
68- if ( this . animListener ) {
69- pos = el . offsetHeight
70- this . animListener ( )
80+ if ( this . animating === true ) {
81+ this . __cleanup ( )
7182 }
7283 else {
7384 this . lastEvent = 'show'
7485 pos = el . scrollHeight
7586 }
7687
77- this . __begin ( el , pos )
88+ this . __begin ( el , pos , done )
7889
79- this . animListener = ( ) => {
80- this . __end ( el , 'hide' )
81- done ( )
82- }
8390 this . timer = setTimeout ( ( ) => {
8491 el . style . height = 0
92+ this . animListener = ( ) => {
93+ this . __end ( el , 'hide' )
94+ }
8595 el . addEventListener ( 'transitionend' , this . animListener )
8696 } , 100 )
8797 }
0 commit comments