Display multiple delayed Noty notifications

I use noty to display notifications using the upper right alert setting. I'm really new to jquery, but know php and mysql enough to get most of the things I want to do.

What I want to do is use mySQL to get the data, to see if it needs to show the user any notifications (made). Then show this notification on the page load, which I also did, although I'm sure there is a more elegant way to show multiple notifications besides repeating the code?

Then I want to set a delay of 1 second for each notification so that they are displayed, so they do not all pop up at once and disappear at the same time. I looked into .delay (), but without knowing jQuery a little better, it is useless to me.

My code is:

$(document).ready(function() { var noty_id = noty({"text":"a message","layout":"topRight","type":"inormation","animateOpen":{"height":"toggle"},"animateClose":{"height":"toggle"},"speed":1000,"timeout":5000,"closeButton":false,"closeOnSelfClick":true,"closeOnSelfOver":false,"modal":false}); var noty_id = noty({"text":"a message","layout":"topRight","type":"inormation","animateOpen":{"height":"toggle"},"animateClose":{"height":"toggle"},"speed":1000,"timeout":5000,"closeButton":false,"closeOnSelfClick":true,"closeOnSelfOver":false,"modal":false}); }); 
+4
source share
1 answer

You can simply use setTimeout() your own Javascript function. This will stop the action after a specified waiting period (milliseconds).

 $(document).ready(function() { var noty_id = noty({"text":"a message","layout":"topRight","type":"inormation","animateOpen":{"height":"toggle"},"animateClose":{"height":"toggle"},"speed":1000,"timeout":5000,"closeButton":false,"closeOnSelfClick":true,"closeOnSelfOver":false,"modal":false}); setTimeout(function() { var noty_id = noty({"text":"a message","layout":"topRight","type":"inormation","animateOpen":{"height":"toggle"},"animateClose":{"height":"toggle"},"speed":1000,"timeout":5000,"closeButton":false,"closeOnSelfClick":true,"closeOnSelfOver":false,"modal":false}); }, 5000) }); 

You can find jQuery Pines better notification system for multiple notification queues.

+2
source

Source: https://habr.com/ru/post/1415211/


All Articles