Notify.js 清除旧通知

Lir*_*ron 3 javascript jquery notifications jquery-ui

我正在使用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");
Run Code Online (Sandbox Code Playgroud)

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

谢谢你,
Liron

Tha*_*gTD 6

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

$('.notifyjs-corner').empty();
Run Code Online (Sandbox Code Playgroud)

遗憾的是,他们没有这样的功能: $.singletonNotify()