我想限制一次最多的公开祝酒次数。我用的是模块和Angular5.我已经配置了如下的全局设置:
ToastrModule.forRoot(
{ maxOpened: 2,
preventDuplicates: true,
timeOut:2000,
closeButton: true,
progressBar:true,
autoDismiss:true,
newestOnTop:true}),
甚至在献上祝酒词之前,先把祝酒词清除干净:
for(let i=0; i<10;i++){
this.toastr.clear();
this.toastr.info(''+i);
}
不过,还是有很多祝酒词同时出现。
发布于 2019-08-26 03:41:16
我创建了一个Stackblitz,它有一个变通方法,一次只允许两个祝酒词,setTimeout为1秒。
for(let i=0; i<10;i++){
((ind)=>{ setTimeout(()=> this.toastr.info(''+i),1000*ind)})(i)
}
发布于 2020-10-04 22:04:02
您可以通过简单的jQuery选择来实现这一点:
const MAX_TOASTS = 2;
toastr.subscribe(function(args) {
if (args.state === 'visible')
{
var toasts = $("#toast-container > *:not([hidden])");
if (toasts && toasts.length > MAX_TOASTS)
toasts[0].hidden = true;
}
});
jQuery selection $("#toast-container > *:not([hidden])")
选择不具有属性hidden
的吐司容器的所有子容器。Toastr,至少在使用CDNVersion2.1.4时,将hidden
属性添加到每一个隐藏/将隐藏的吐司中。
将吐司的隐藏属性设置为true
隐藏它。
https://stackoverflow.com/questions/57655959
复制相似问题