gpt4 book ai didi

javascript - GetUIkIt 3 通知关闭事件?

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:58:05 24 4
gpt4 key购买 nike

我需要知道 UIKit 通知何时关闭。

UIkit 通知插件 ( https://getuikit.com/docs/notification ) 提到它有一个关闭事件。是否可以将其用于以编程方式触发的实例?

例如

UIkit.notification({
message: 'my-message!',
status: 'primary',
timeout: null
});
UIKit.o

我试过将通知放在一个变量上(如建议的 https://getuikit.com/docs/javascript#programmatic-use ,它甚至声明 您将收到初始化的组件作为返回值 - 但您没有)

let foo = UIkit.notification('message'); // foo is undefined

我试过链接 on 方法

UIkit.notification.on('close', function() { ... }); // on is undefined

但是 .on 方法是 UIkit.util.on($el, event, fn) 的一部分并且没有 $el 当以编程方式调用通知时。

我能想到的唯一其他方法是将突变观察器放在 body 上并观察通知元素以更改状态,但这似乎有点矫枉过正。

最佳答案

您可以存储通知的句柄...

warning_notification = UIkit.notification({message: 'Warning message...',
status: 'warning', timeout: 1000});

... 并检查这是否是关闭事件的来源:

UIkit.util.on(document, 'close', function(evt) {
if (evt.detail[0] === warning_notification) {
alert('Warning notification closed');
}
});

现在,您只会在该通知关闭时看到警报。

Check out this demo .

关于javascript - GetUIkIt 3 通知关闭事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49374524/

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