Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using timeouts with toastr

Most of the toastr demos are client side only.

If I get a server push of this json data

   [
    {"msg": "Mortgage bill paid", "t": "i"}
    {"msg": "Account Balance below $3000", "t": "i"}
    {"msg": "Received Car payment request", "t": "w"}
    ]

How would I use toastr read through items and publish 'info' for 1 and 2, "warning" for 3, lower right is ok. I would like a delay of 2000 between toasts so the toast dont come at the same time.

Can you point me to example that show something similar. Can toastr do this. Timed messaging in a sense.

like image 967
Merlin Avatar asked Apr 17 '26 00:04

Merlin


2 Answers

This is the exact thing you need I guess

setTimeout((function() {
   toastr.info('MESSAGE TITLE', 'message content', {options});
}), delay);

toastr.options = {
  "closeButton": true,
  "debug": false,
  "newestOnTop": false,
  "progressBar": false,
  "positionClass": "toast-top-center",
  "preventDuplicates": false,
  "onclick": null,
  "showDuration": "300",
  "hideDuration": "1000",
  "timeOut": "5000",
  "extendedTimeOut": "1000",
  "showEasing": "swing",
  "hideEasing": "linear",
  "showMethod": "fadeIn",
  "hideMethod": "fadeOut"
}
like image 99
hafiz ali Avatar answered Apr 18 '26 14:04

hafiz ali


You could loop through the array and call toastr['info'] or toastr['warning'] (map the i to info, for example). FOr delays, you could use a timeout and delay the messages by 2000 ms for each.

timeout(toastr['info']('your message'), 2000);
like image 36
John Papa Avatar answered Apr 18 '26 13:04

John Papa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!