Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

toast notification over 'overlay'

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?

like image 661
Maxsteel Avatar asked Aug 25 '14 10:08

Maxsteel


People also ask

What is the difference between toast and notification?

A toast is a small display on the bottom of the screen. A notification is displayed in the top menu bar.

Where should toast notifications appear?

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.

How long should toast notification last?

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.

How do you stack toasts?

Stacking. You can stack toasts by wrapping them in a toast container, which will vertically add some spacing.


1 Answers

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 :-)

like image 181
Rahul Patil Avatar answered Sep 22 '22 22:09

Rahul Patil