Notify.js清除旧通知

Notify.js clear old notifications

本文关键字:通知 清除 js Notify      更新时间:2023-09-26

我正在使用Notify.js在我的网站上显示通知。我遇到了一个问题,我添加通知会显示它们,然后,如果我想显示不同的通知并添加它,我也会看到旧的通知。工作流程为:

  1. 用户输入数据
  2. 用户按下按钮
  3. 数据已验证
  4. 已添加错误通知
  5. 继续,直到一切都正确

为了添加通知,我使用以下内容:

var noteOption = {
    // whether to hide the notification on click
    clickToHide : true,
    // whether to auto-hide the notification
    autoHide : false,
    globalPosition : 'bottom right',
    // default style
    style : 'bootstrap',
    // default class (string or [string])
    className : 'error',
    // show animation
    showAnimation : 'slideDown',
    // show animation duration
    showDuration : 400,
    // hide animation
    hideAnimation : 'slideUp',
    // hide animation duration
    hideDuration : 200,
    // padding between element and notification
    gap : 10
}
var note = "My Error Message"
$.notify.defaults(noteOption);
$.notify(note, "error");

所以现在的实际问题是,在添加新通知之前,我如何清除通知?

谢谢,
Liron

这是因为您调用的函数总是返回Notification的新实例最好的方法是清除旧的通知容器:

$('.notifyjs-corner').empty();

遗憾的是,它们没有类似的功能:$.singletonNotify()

这对我很有效:

$.notifyClose();
$.notify({...});

https://github.com/mouse0270/bootstrap-notify/issues/136#issuecomment-204051563