Animations
17 Feb 20229 minutes to read
The toast control supports custom animations for both shows and hide actions from the provided animation
option of the Animation
library.
The default animation is given as FadeIn
for showing the toast and FadeOut
for hiding the toast.
The following sample demonstrates some types of animations that suit toast. You can check all the animation effects here.
<div id="default" style="padding-bottom:75px;">
<div class='row'> <ejs-button id="show_toast" content="Show Toast" cssClass="e-btn"></ejs-button> </div>
<div class='row'>
<div class="col-md-6">
<label> Show Animation </label>
</div>
<div class="col-md-6">
<ejs-dropdownlist id="showAnimation" dataSource="@ViewBag.data" placeholder="Select a animate type" index="0" popupHeight="200px" change="valueChange">
<e-dropdownlist-fields text="Value" value="Id"></e-dropdownlist-fields>
</ejs-dropdownlist>
</div>
</div>
<div class='row'>
<div class="col-md-6">
<label> Hide Animation </label>
</div>
<div class="col-md-6">
<ejs-dropdownlist id="hideAnimation" dataSource="@ViewBag.data" index="0" placeholder="Select a animate type" change="valueChange1">
<e-dropdownlist-fields text="Value" value="Id"></e-dropdownlist-fields>
</ejs-dropdownlist>
</div>
</div>
<ejs-toast id="element" title="Matt sent you a friend request" content="You have a new friend request yet to accept">
<e-toast-position X="Right" Y="Bottom"></e-toast-position>
<e-toast-animationsettings>
<e-toast-animationsettingsshow effect="SlideRightIn" duration="400"></e-toast-animationsettingsshow>
<e-toast-animationsettingshide effect="SlideRightOut" duration="400"></e-toast-animationsettingshide>
</e-toast-animationsettings>
</ejs-toast>
</div>
<script type="text/javascript">
setTimeout(
() => {
var toastObj = document.getElementById('element').ej2_instances[0];
toastObj.target = document.body;
toastObj.show();
}, 1000);
document.getElementById("show_toast").addEventListener('click', function () {
var toastObj = document.getElementById('element').ej2_instances[0];
toastObj.show();
});
function valueChange(e) {
var toastObj = document.getElementById('element').ej2_instances[0];
toastObj.animation.show.effect = e.value;
}
function valueChange1(e) {
var toastObj = document.getElementById('element').ej2_instances[0];
toastObj.animation.hide.effect = e.value;
}
</script>
<style>
#default {
width: 600px;
margin: 0 auto;
}
.row {
margin: 15px;
}
</style>
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.data = new Animation().Animations();
return View();
}
public class Animation
{
public string Value { get; set; }
public string Id { get; set; }
public List<Animation> Animations()
{
List<Animation> animation = new List<Animation>
{
new Animation { Id = "FadeIn", Value = "Fade In" },
new Animation { Id = "FadeZoomIn", Value = "Fade Zoom In" },
new Animation { Id = "FadeZoomOut", Value = "Fade Zoom Out" },
new Animation { Id = "FlipLeftDownIn", Value = "Flip Left Down In" },
new Animation { Id = "FlipLeftDownOut", Value = "Flip Left Down Out" },
new Animation { Id = "FlipLeftUpIn", Value = "Flip Left Up In" },
new Animation { Id = "FlipLeftUpOut", Value = "Flip Left Up Out" },
new Animation { Id = "FlipRightDownIn", Value = "Flip Right Down In" },
new Animation { Id = "FlipRightUpIn", Value = "Flip Right Up In" },
new Animation { Id = "FlipRightUpOut", Value = "Flip Right Up Out" },
new Animation { Id = "SlideBottomIn", Value = "Slide Bottom In" },
new Animation { Id = "SlideBottomOut", Value = "Slide Bottom Out" },
new Animation { Id = "SlideLeftIn", Value = "Slide Left In" },
new Animation { Id = "SlideLeftOut", Value = "Slide Left Out" },
new Animation { Id = "SlideRightIn", Value = "Slide Right In" },
new Animation { Id = "SlideRightOut", Value = "Slide Right Out" },
new Animation { Id = "SlideTopIn", Value = "Slide Top In" },
new Animation { Id = "SlideTopOut", Value = "Slide Top Out" },
new Animation { Id = "ZoomIn", Value = "Zoom In" },
new Animation { Id = "ZoomOut", Value = "Zoom Out" }
};
return animation;
}
}
}