首页 > 解决方案 > Toastr onhidden function 只有成功消息

问题描述

我正在使用 toastr 库并拥有以下代码:

toastr.options = {
  "closeButton": true,
  "newestOnTop": true,
  "progressBar": true,
  "positionClass": "toast-bottom-right",
  "preventDuplicates": true,
  "showDuration": 400,
  "hideDuration": 400,
  timeOut: 2500,
  "showEasing": "swing",
  "hideEasing": "linear",
  "showMethod": "fadeIn",
  "hideMethod": "fadeOut",
  "newestOnTop": true,
  "onHidden": function() { console.log("HIDE") }
}

如果消息将消失(隐藏),则将启动一个功能。这很好用!但是有没有一个选项,只有当我发出 toastr.success 消息时才会启动 onhidden 函数?

标签: jquerytoastr

解决方案


您可以订阅toastr全局回调并查看您感兴趣的通知:

function toastrActions(response) {
    if(response.state == 'hidden') {
        console.log("Toastr #",response.toastId,"is hidden. Type:",response.map.type);
    }
}

toastr.subscribe(toastrActions);

推荐阅读