Animation in EJ2 JavaScript Tooltip control
8 May 202310 minutes to read
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.
var tooltip = new ej.popups.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="https://cdn.syncfusion.com/ej2/28.1.33/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-popups/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/28.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="target">
Show tooltip
</div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</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 theshowTipPointer
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.
var tooltip = new ej.popups.Tooltip({
content: 'Tooltip content',
opensOn: 'Custom'
});
tooltip.appendTo('#target');
document.getElementById('target').addEventListener("click", function () {
if (this.getAttribute("data-tooltip-id")) {
var closeAnimation = { effect: 'FadeOut', duration: 1000 };
tooltip.close(closeAnimation);
}
else {
var openAnimation = { 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="https://cdn.syncfusion.com/ej2/28.1.33/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-popups/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/28.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<div id="container">
<div id="target">
Show tooltip
</div>
</div>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</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.
var tooltip = new ej.popups.Tooltip({
target: '.circletool',
closeDelay: 1000,
animation: { open: { effect: 'ZoomIn', duration: 500 }, close: { effect: 'ZoomOut', duration: 500 } },
beforeRender: onBeforeRender,
afterClose: onAfterClose
});
function onBeforeRender(args) {
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) {
// 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="https://cdn.syncfusion.com/ej2/28.1.33/ej2-base/styles/material.css" rel="stylesheet">
<link href="https://cdn.syncfusion.com/ej2/28.1.33/ej2-popups/styles/material.css" rel="stylesheet">
<script src="https://cdn.syncfusion.com/ej2/28.1.33/dist/ej2.min.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<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>
<script>
var ele = document.getElementById('container');
if(ele) {
ele.style.visibility = "visible";
}
</script>
<script src="index.js" type="text/javascript"></script>
</body></html>