How to change animation settings in React
04 Sep 20268 minutes to read
The React ContextMenu component provides customizable animation effects through the animationSettings property. This allows you to control how the ContextMenu appears and disappears, enhancing the user experience with smooth visual transitions. The same animationSettings value is applied to both the root menu and any submenu popups.
The supported animation effects for the React ContextMenu are:
| Effect | Description |
|---|---|
| None | No animation; the React Context Menu appears instantly. |
| SlideDown | Animates the React Context Menu with a sliding motion from top to bottom. |
| ZoomIn | Scales the React Context Menu from small to full size with a zoom effect. |
| FadeIn | Gradually increases the opacity of the React Context Menu from transparent to visible. |
The animationSettings property accepts an object with three configurable options: effect (animation type), duration (animation time in milliseconds), and easing (transition timing function). The default settings use SlideDown effect with 400ms duration and ease timing.
The following sample demonstrates how to configure React Context Menu with FadeIn effect and a custom duration of 800ms.
import { enableRipple } from '@syncfusion/ej2-base';
import { ContextMenuComponent } from '@syncfusion/ej2-react-navigations';
import * as React from 'react';
import * as ReactDom from 'react-dom';
enableRipple(true);
function App() {
let animation = {
duration: 800,
effect: 'FadeIn'
};
let menuItems = [
{
text: 'Show All Bookmarks'
},
{
items: [
{
items: [
{
text: 'Google'
},
{
text: 'Gmail'
}
],
text: 'Most Visited'
},
{
text: 'Recently Added'
}
],
text: 'Bookmarks Toolbar'
}
];
return (<div className="container">
<div id='target'>Right click / Touch hold to open the ContextMenu</div>
<ContextMenuComponent id='contextmenu' target='#target' items={menuItems} animationSettings={animation}/>
</div>);
}
export default App;
ReactDom.render(<App />, document.getElementById('element'));import { enableRipple } from '@syncfusion/ej2-base';
import { ContextMenuComponent, MenuItemModel } from '@syncfusion/ej2-react-navigations';
import * as React from 'react';
import * as ReactDom from 'react-dom';
enableRipple(true);
function App() {
let animation: any = {
duration: 800,
effect: 'FadeIn'
};
let menuItems: MenuItemModel[] = [
{
text: 'Show All Bookmarks'
},
{
items: [
{
items: [
{
text: 'Google'
},
{
text: 'Gmail'
}
],
text: 'Most Visited'
},
{
text: 'Recently Added'
}
],
text: 'Bookmarks Toolbar'
}];
return (
<div className="container">
<div id='target'>Right click / Touch hold to open the ContextMenu</div>
<ContextMenuComponent id='contextmenu' target='#target'
items={menuItems} animationSettings={animation}/>
</div>
);
}
export default App;
ReactDom.render(<App />,document.getElementById('element'));