gpt4 book ai didi

javascript - 屏幕上有多个通知时,关闭通知将关闭最后一个通知

转载 作者:行者123 更新时间:2023-12-03 04:04:01 25 4
gpt4 key购买 nike

我正在使用NOTY (通知库)版本3.0.0显示来自 JavaScript 的通知弹出窗口。

虽然屏幕上有多个通知,但当我单击关闭按钮时,它始终会关闭屏幕上放置的最后一个通知。我知道这是因为变量 n 总是被示例代码中的最后一个通知对象覆盖。但是,我在文档中没有找到有关如何在多个通知的情况下处理通知关闭的任何线索。

我应该创建一个通知对象数组,然后像 n[i].close() 这样调用 .close() 函数,还是有更好的方法来实现这一点?请帮忙。

示例代码:

var n = new Noty({
type: 'success',
layout: 'bottomRight',
theme: 'relax',
text: "<b>Testing 2<br/><br/> ",
timeout: false,
closeWith: ['button'],
animation: {
open: 'noty_effects_open',
close: 'noty_effects_close'
},
buttons: [
Noty.button('CLOSE', 'btn btn-error', function () {
console.log('button 2 clicked');
n.close();
})
],
}).show();

最佳答案

我认为您可以使用queue功能,您可以将多个对象推送到队列变量,并可以使用下面的示例来操作这些对象

Noty.closeAll(); // Closes all notifications
Noty.closeAll('myCustomQueueName'); // Closes all notifications with queue named 'myCustomQueueName'

Noty.setMaxVisible(10); // Sets the maxVisible notification count for global queue;
Noty.setMaxVisible(10, 'myCustomQueueName'); // Sets the maxVisible notification count for 'myCustomQueueName' queue;

关于javascript - 屏幕上有多个通知时,关闭通知将关闭最后一个通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44638698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com