@@ -103,15 +103,21 @@ function assembleArrow(
103103 return `<div style="${ styleCss . join ( '' ) } "></div>` ;
104104}
105105
106- function assembleTransition ( duration : number , onlyFade ? : boolean ) : string {
106+ function assembleTransition ( duration : number , onlyFadeTransition : boolean , enableDisplayTransition : boolean ) : string {
107107 const transitionCurve = 'cubic-bezier(0.23,1,0.32,1)' ;
108- let transitionOption = ` ${ duration / 2 } s ${ transitionCurve } ` ;
109- let transitionText = `opacity${ transitionOption } ,visibility${ transitionOption } ` ;
110- if ( ! onlyFade ) {
108+ let transitionOption = '' ;
109+ let transitionText = '' ;
110+ if ( enableDisplayTransition ) {
111+ transitionOption = ` ${ duration / 2 } s ${ transitionCurve } ` ;
112+ transitionText = `opacity${ transitionOption } ,visibility${ transitionOption } ` ;
113+ }
114+ if ( ! onlyFadeTransition ) {
111115 transitionOption = ` ${ duration } s ${ transitionCurve } ` ;
112- transitionText += env . transformSupported
113- ? `,${ CSS_TRANSFORM_VENDOR } ${ transitionOption } `
114- : `,left${ transitionOption } ,top${ transitionOption } ` ;
116+ transitionText += ( transitionText . length ? ',' : '' ) + (
117+ env . transformSupported
118+ ? `${ CSS_TRANSFORM_VENDOR } ${ transitionOption } `
119+ : `,left${ transitionOption } ,top${ transitionOption } `
120+ ) ;
115121 }
116122
117123 return CSS_TRANSITION_VENDOR + ':' + transitionText ;
@@ -173,7 +179,12 @@ function assembleFont(textStyleModel: Model<TooltipOption['textStyle']>): string
173179 return cssText . join ( ';' ) ;
174180}
175181
176- function assembleCssText ( tooltipModel : Model < TooltipOption > , enableTransition ?: boolean , onlyFade ?: boolean ) {
182+ function assembleCssText (
183+ tooltipModel : Model < TooltipOption > ,
184+ enableTransition : boolean ,
185+ onlyFadeTransition : boolean ,
186+ enableDisplayTransition : boolean
187+ ) {
177188 const cssText : string [ ] = [ ] ;
178189 const transitionDuration = tooltipModel . get ( 'transitionDuration' ) ;
179190 const backgroundColor = tooltipModel . get ( 'backgroundColor' ) ;
@@ -186,8 +197,9 @@ function assembleCssText(tooltipModel: Model<TooltipOption>, enableTransition?:
186197 const boxShadow = `${ shadowOffsetX } px ${ shadowOffsetY } px ${ shadowBlur } px ${ shadowColor } ` ;
187198
188199 cssText . push ( 'box-shadow:' + boxShadow ) ;
189- // Animation transition. Do not animate when transitionDuration is 0.
190- enableTransition && transitionDuration && cssText . push ( assembleTransition ( transitionDuration , onlyFade ) ) ;
200+ // Animation transition. Do not animate when transitionDuration <= 0.
201+ enableTransition && transitionDuration > 0
202+ && cssText . push ( assembleTransition ( transitionDuration , onlyFadeTransition , enableDisplayTransition ) ) ;
191203
192204 if ( backgroundColor ) {
193205 cssText . push ( 'background-color:' + backgroundColor ) ;
@@ -284,6 +296,8 @@ class TooltipHTMLContent {
284296 */
285297 private _longHideTimeout : number ;
286298
299+ private _enableDisplayTransition : boolean ;
300+
287301 constructor (
288302 api : ExtensionAPI ,
289303 opt : TooltipContentOption
@@ -376,6 +390,9 @@ class TooltipHTMLContent {
376390 // update alwaysShowContent
377391 this . _alwaysShowContent = alwaysShowContent ;
378392
393+ this . _enableDisplayTransition = tooltipModel . get ( 'displayTransition' )
394+ && tooltipModel . get ( 'transitionDuration' ) > 0 ;
395+
379396 // update className
380397 this . el . className = tooltipModel . get ( 'className' ) || '' ;
381398
@@ -395,7 +412,7 @@ class TooltipHTMLContent {
395412 }
396413 else {
397414 style . cssText = gCssText
398- + assembleCssText ( tooltipModel , ! this . _firstShow , this . _longHide )
415+ + assembleCssText ( tooltipModel , ! this . _firstShow , this . _longHide , this . _enableDisplayTransition )
399416 // initial transform
400417 + assembleTransform ( styleCoord [ 0 ] , styleCoord [ 1 ] , true )
401418 + `border-color:${ convertToColorString ( nearPointColor ) } ;`
@@ -499,8 +516,13 @@ class TooltipHTMLContent {
499516
500517 hide ( ) {
501518 const style = this . el . style ;
502- style . visibility = 'hidden' ;
503- style . opacity = '0' ;
519+ if ( this . _enableDisplayTransition ) {
520+ style . visibility = 'hidden' ;
521+ style . opacity = '0' ;
522+ }
523+ else {
524+ style . display = 'none' ;
525+ }
504526 env . transform3dSupported && ( style . willChange = '' ) ;
505527 this . _show = false ;
506528 this . _longHideTimeout = setTimeout ( ( ) => this . _longHide = true , 500 ) as any ;
0 commit comments