I know it's not what toastr (or toast notifs in general) are meant to be used for, but I want to use them as a modal notification
. My idea is following.
On toast show:
toastr.options.onShown = function() { //Create an overlay on the entire page}
Overlay:
#overlay {
background-color: rgba(0, 0, 0, 0.8);
z-index: 999;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: none;
}
And on toast close:
toastr.options.onHidden = function() { //make overlay go away }
Also, I'm setting timeout of toast to 0 so it won't disappear by itself.
Question: I want the toast notification to stay atop the overlay and not behind it as overlay will cover everything. How can I do it?
A toast is a small display on the bottom of the screen. A notification is displayed in the top menu bar.
Toasts (Android only) are primarily used for system messaging. They also display at the bottom of the screen, but may not be swiped off-screen.
Toasts automatically disappear after a timeout. If your app targets Android 12 (API level 31) or higher, its toast is limited to two lines of text and shows the application icon next to the text. Be aware that the line length of this text varies by screen size, so it's good to make the text as short as possible.
Stacking. You can stack toasts by wrapping them in a toast container, which will vertically add some spacing.
You are doing it right..
Just add
<div id="overlay"></div>
in body somewhere. Add your required style in stylesheet.
In toastr.options.onShown
callback, add show overlay $("#overlay").show();
and in toastr.options.onHidden
callback hide it.. $("#overlay").hide();
Toaster has id toast-container
which has z-index
999999. So in order to move overlay below toastr, set z-index below 999999.. Which is the default case in your stylesheet..
You should be good to go :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With