如何以编程方式关闭notify.js通知?

时间:2017-01-23 11:34:36

标签: javascript jquery notifyjs

在下面的示例中,我试图通过点击notify.js API高级示例中的suggeseted按钮来强行关闭已打开的通知,如何做到这一点?



function CLOSE() {
  $('#btn').trigger('notify-hide');
}
$(document).ready(function() {

  $('#btn').notify('test note', {
    position: 'right'
  });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/notify/0.4.2/notify.js"></script>

<button onClick="CLOSE()" id="btn" class="tst">Test</button>
&#13;
&#13;
&#13;

3 个答案:

答案 0 :(得分:1)

您必须触发代表notify-hide元素的div的{​​{1}}个事件。

notify
function CLOSE() {
  $('.notifyjs-wrapper').trigger('notify-hide');
}
$(document).ready(function() {

  $('#btn').notify('test note', {
    position: 'right'
  });
});

以下是显示DOM结构外观的片段:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/notify/0.4.2/notify.js"></script>

<button onClick="CLOSE()" id="btn" class="tst">Test</button>

答案 1 :(得分:0)

我用过这种方法。

$(".notifyjs-arrow").html('<i class="fas fa-times-circle" style="position:absolute; text-align:right;top:-7px;color:red;right:-320px"></i>');

enter image description here

答案 2 :(得分:0)

如果您有多个通知,并且不需要一次将其全部关闭,则可以向通知中添加特定的类,稍后再找到该通知元素并将其隐藏。

// first ajax request started
$.notify("The notification #1", {className: "info n1", autoHide: false});
...
// second ajax request started
$.notify("The notification #2", {className: "info n2", autoHide: false});
...
// first ajax request done
$(".n1").toggle('notify-hide');

第二个通知不会隐藏。