|
That's neat. I use a similar method, but use Swal2 Toast method. I use it as a js function so I can use it anywhere. it is called using. // set variables var title = 'Message title'; var 'message' = 'some message'; var icon = 'e'; // 'e' = Error, 'i' = info, 's' = success, var timer = 10; //seconds var position = 1; // center screen // usage showToast(title,message,icon,timer, position);
// function function showToast(title, message, imgIcon, duration, fc) { // postions:'top', 'top-start', 'top-end', 'center', 'center-start', 'center-end', 'bottom', 'bottom-start', or 'bottom-end' var myBordercol = ''; var myPosition = ''; if (fc == 0) {myPosition = 'bottom-end';} // appears at bottom right of screen if (fc == 1) {myPosition = "center";} if (fc == 2) {myPosition = 'top-start';} if (fc == 3) {myPosition = 'top-end';} if (fc == 4) {myPosition = 'center-end';} var myIcon = "info"; // set a default imgIcon = typeof imgIcon === 'string' && imgIcon.length > 0 ? imgIcon : 'info'; if (imgIcon.startsWith('e')) {myBordercol = "red";myIcon = "error";} else if (imgIcon.startsWith('s')) {myBordercol = "green";myIcon = "success";} else if (imgIcon.startsWith('i')) {myBordercol = "blue";myIcon = "info";} else if (imgIcon.startsWith('w')) {myBordercol = "orange";myIcon = "warning"; } if (duration !== 0) {var myDuration = duration || 3;} else {var myDuration = 5; } myDuration = myDuration * 1000; if (myDuration > 0 && myDuration < 1000) {myDuration = 3000;} Swal.fire({ toast: true, width: 450, showClass: { popup: '' }, position: myPosition, icon: myIcon || 'info', timer: myDuration > 0 ? myDuration : null, title: '<div style="font-size: 16px; font-weight: bold;">' + (title || 'Information') + '</div>', // Concatenated title html: '<div><font size="3">' + message + '</font></div>', showConfirmButton: false, timerProgressBar: myDuration > 0, showCloseButton: true, customClass: {popup: 'custom-toast'}, didOpen: function(toast) { if (myBordercol) { toast.style.border = '2px solid ' + myBordercol; } } }); } Example.
When it runs an animated progressbar at the bottom of the popup shows. Also, it's not modal so a user can continue what they were doing without too much interruption.
|