Customize progress bar theme and sizing
17 Feb 20226 minutes to read
By default, the progress bar appears based on the theme stylings and dimensions. You can customize the progress bar stylings using custom CSS or event functions.
The following sample demonstrates customizing the progress bar stylings using the BeforeOpen
event.
<div style="width:400px;margin:0 auto;">
@Html.EJS().Toast("element").Title("Matt sent you a friend request").Position(p => p.X("Right").Y("Bottom")).Content("You have a new friend request yet to accept").BeforeOpen("onBeforeOpen").ShowProgressBar(true).Render()
<div class="row">
@Html.EJS().Button("show_toast").Content("Show Toast").CssClass("e-btn").Render()
</div>
<div class="row" style="padding-top: 20px">
<div class="e-float-input">
<input class="e-input" id="progressHeight" name="Digits" value="4" required>
<span class="e-float-line"></span>
<label class="e-float-text" for="Digits">Progress Bar Height</label>
</div>
</div>
<div class="row" style="padding-top: 20px">
<div class="col-md-6">
<label> Progress Bar Color </label>
</div>
<div class="col-md-6">
@Html.EJS().DropDownList("Progress").Placeholder("Select a animate type").PopupHeight("150px").Index(0).DataSource(
(IEnumerable<object>)ViewBag.data).Change("valueChange").Fields(e=>e.Value("Id").Text("Value")).Render()
</div>
</div>
</div>
<script type="text/javascript">
setTimeout(
() => {
var toastObj = document.getElementById('element').ej2_instances[0];
toastObj.target = document.body;
toastObj.show();
}, 200);
function onBeforeOpen(e) {
var progress = e.element.querySelector('.e-toast-progress');
progress.style.height = document.getElementById('progressHeight').value + 'px';
var listObjprogressColor = document.getElementById('Progress').ej2_instances[0];
progress.style.backgroundColor = listObjprogressColor.value;
}
function valueChange(e) {
var toastObj = document.getElementById('element').ej2_instances[0];
var listObjprogressColor = document.getElementById('Progress').ej2_instances[0];
var progressEles = toastObj.element.querySelectorAll('.e-toast-progress');
progressEles.forEach((ele) => {
ele.style.backgroundColor = listObjprogressColor.value;
})
}
document.getElementById("show_toast").addEventListener('click', function () {
var toastObj = document.getElementById('element').ej2_instances[0];
toastObj.show();
});
</script>
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.data = new Color().Colors();
return View();
}
public class Color
{
public string Value { get; set; }
public string Id { get; set; }
public List<Color> Colors()
{
List<Color> color = new List<Color>();
position.Add(new Color { Id = "red", Value = "Red" });
position.Add(new Color { Id = "cyan", Value = "Cyan" });
position.Add(new Color { Id = "blue", Value = "Blue" });
position.Add(new Color { Id = "yellow", Value = "Yellow" });
position.Add(new Color { Id = "pink", Value = "Pink" });
return color;
}
}
}