Search results

Animation

To animate the Tooltip, a set of specific animation effects are available, and it can be controlled using the animation property. The animation property also allows you to set delay, duration, and various other effects of your choice.

AnimationModel is derived from base to apply the chosen animation effect, duration, etc. on Tooltips.

By default, Tooltip entrance occurs over 150 ms using the ease-out timing function. It exits also at 150 ms, but uses ease-in timing function.

Source
Preview
index.ts
index.html
import { Tooltip } from '@syncfusion/ej2-popups';

let tooltip: Tooltip = new Tooltip({
    content: 'Tooltip content',
    animation: {
        open: { effect: 'ZoomIn', duration: 1000, delay: 0 },
        close: { effect: 'ZoomOut', duration: 500, delay: 0 }
    }
});
tooltip.appendTo('#target');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Tooltip</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>LOADING....</div>
    <div id='container'>
        <div id="target">
            Show tooltip
        </div>
    </div>
</body>

</html>

The default animation effect for the Tooltip is set to FadeIn for its open action, and FadeOut for its close action. The default duration is set to 150 ms and delay is set to 0.

Animation effects

The animation effects that are applicable to Tooltips are:

  • FadeIn
  • FadeOut
  • FadeZoomIn
  • FadeZoomOut
  • FlipXDownIn
  • FlipXDownOut
  • FlipXUpIn
  • FlipXUpOut
  • FlipYLeftIn
  • FlipYLeftOut
  • FlipYRightIn
  • FlipYRightOut
  • ZoomIn
  • ZoomOut
  • None

When the effect is specified as none, no effect will be applied to the Tooltip, and animation is considered to be set to off.

Some of the above animation effects suits the Tooltip better when its tip pointer is hidden. This can be achieved by setting the showTipPointer to false.

Animating via open/close methods

Animations can also be applied on Tooltips dynamically through open and close methods. These methods accept the animation model as an optional parameter. If you pass TooltipAnimationSettings, animation takes this model; otherwise, it takes the values from the animation property. It is also possible to pass different animations for Tooltips on each target.

Refer to the code snippet below to apply animations using public methods.

Source
Preview
index.ts
index.html
import { Tooltip, TooltipAnimationSettings } from '@syncfusion/ej2-popups';

let tooltip: Tooltip = new Tooltip({
    content: 'Tooltip content',
    opensOn: 'custom'
});
tooltip.appendTo('#target');


document.getElementById('target').addEventListener("click", function () {
    if (this.getAttribute("data-tooltip-id")) {
        let closeAnimation: TooltipAnimationSettings = { effect: 'FadeOut', duration: 1000 }
        tooltip.close(closeAnimation);
    } else {
        let openAnimation: TooltipAnimationSettings = { effect: 'FadeIn', duration: 1000 }
        tooltip.open(this, openAnimation);
    }
});
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Tooltip</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>LOADING....</div>
    <div id='container'>
        <div id="target">
            Show tooltip
        </div>
    </div>
</body>

</html>

Apply transition

The transition effect can be applied on Tooltips by using the beforeRender event as given in the following work-around code example.

Source
Preview
index.ts
index.html
import { Tooltip, TooltipEventArgs } from '@syncfusion/ej2-popups';
let tooltip: Tooltip = new Tooltip({
    target: '.circletool',
    closeDelay: 1000,
    animation: { open: { effect: 'ZoomIn', duration: 500 }, close: { effect: 'ZoomOut', duration: 500 } },
    beforeRender: onBeforeRender,
    afterClose: onAfterClose
});
function onBeforeRender(args: TooltipEventArgs): void {
    if (args.element) {
        // here prevent animation while apply transition
        this.animation = { open: { effect: 'None' } };
        args.element.style.display = 'block';
        args.element.style.transitionProperty = 'left,top';
        args.element.style.transitionDuration = '1000ms';
    }
}
function onAfterClose(args: TooltipEventArgs): void {
    // restore the animation effects
    this.animation = { open: { effect: 'ZoomIn', duration: 500 }, close: { effect: 'ZoomOut', duration: 500 } };
}
tooltip.appendTo('#box');
<!DOCTYPE html>
<html lang="en">

<head>
    <title>EJ2 Tooltip</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="Typescript UI Controls" />
    <meta name="author" content="Syncfusion" />
    <link href="index.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
    <link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
    <script src="systemjs.config.js"></script>
</head>

<body>
    <div id='loader'>LOADING....</div>
    <div id='container'>
        <h3> Transition effect </h3>
        <div id="box" class="e-prevent-select">
            <div class="circletool" style="top:18%;left:5%" title="This is Turtle !!!"></div>
            <div class="circletool" style="top:30%;left:30%" title="This is Snake !!!"></div>
            <div class="circletool" style="top:80%;left:80%" title="This is Croc !!!"></div>
            <div class="circletool" style="top:65%;left:50%" title="This is String Ray !!!"></div>
            <div class="circletool" style="top:75%;left:15%" title="This is Blob Fish !!!"></div>
            <div class="circletool" style="top:30%;left:70%" title="This is Mammoth !!!"></div>
        </div>
    </div>
</body>

</html>