jquery - 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 函数?
解决方案
您可以订阅toastr
全局回调并查看您感兴趣的通知:
function toastrActions(response) {
if(response.state == 'hidden') {
console.log("Toastr #",response.toastId,"is hidden. Type:",response.map.type);
}
}
toastr.subscribe(toastrActions);
推荐阅读
- angular - 错误 - 此命令只能在 CLI 项目内运行
- android - Android Wear:无法通过 wifi 或蓝牙连接手表
- android - Android studio 无法将 apk 安装到 Xiaomi Note5A (Redmi) 中(安装失败并显示 INSTALL_FAILED_USER_RESTRICTED 消息:)
- objective-c - Swift 4:将 Objective-c 转换为 Swift 时,非标称类型“T”不支持显式初始化
- jmeter - 如何使用后端侦听器将 jmeter 结果推送到多个数据库?
- php - 在 Woocommerce 的单个产品页面中添加产品备注字段
- macos - 在 macOS 上安装 VMware Player 时出现问题
- android - 如何使颤振应用程序响应?
- r - 扫描一列以查找超过某个值的值,并将整个列移动到 R 中的新数据框中
- spring - Spring Framework:由于浏览器中的多个选项卡而获取错误的 processFormSubmission() 对象