简体   繁体   English

noty:关闭“假”不工作?

[英]noty: closable “false” not working?

I am using "needim noty" jquery notification plugin, I am trying to close the notification only programatically, I saw option closable to stop closing notification. 我正在使用“needim noty” jquery通知插件,我试图仅以编程方式closable通知,我看到选项closable以停止关闭通知。 but when I am trying notification closing with click? 但是当我尝试通过点击关闭通知时?

any ideas to stop closing with click and do it programmatically? 任何想要通过点击停止关闭的想法并以编程方式执行?

"noty plugin" “noty插件”

Refers "closable" 指“可关闭”

My Issue 我的问题

I needed something like this in the past and this is what I did: 我过去需要这样的东西,这就是我所做的:

To stop closing with click, hover and close button I changed the template and closeWith plugin options: 要通过单击,悬停和关闭按钮停止关闭,我更改了模板并关闭了插件选项:

$.noty.defaults.closeWith = ["button"];
$.noty.defaults.template = '<div class="noty_message"><span class="noty_text"></span></div>';

This way noty will make all notifications close only when clicking on the template close button but since I removed it from the template it is not possible. 这种方式只会在单击模板关闭按钮时关闭所有通知,但由于我从模板中删除它是不可能的。

Note that you don't need to make this the default noty behavior. 请注意,您不需要将此作为默认的noty行为。 You can use it only in some cases by using this options only when you need. 只有在需要时才可以在某些情况下使用此选项。

To close it programmatically I used $.noty.close(id) and $.noty.closeAll() functions. 为了以编程方式关闭它,我使用了$ .noty.close(id)$ .noty.closeAll()函数。 To use the first one you need the notification ID that is generated when it is created. 要使用第一个,您需要在创建时生成的通知ID。 You can get it this way and store it to use when you need to close a specific notification. 您可以通过这种方式获取并存储它,以便在需要关闭特定通知时使用。

$n = noty({text: 'noty - a jquery notification library!'});
var noty_id = $n.options.id;

See this working demo for a better understanding 有关更好的理解,请参阅此工作演示

Edit: 编辑:

To set this on the fly for only some notifications you need to pass the options like this: 要仅为某些通知动态设置,您需要传递如下选项:

var $n = noty({
    text: 'I have a special behaviour',
    template: '<div class="noty_message"><span class="noty_text"></span></div>',
    closeWith: ["button"]
});

See this working demo for a better understanding 有关更好的理解,请参阅此工作演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM