我使用bootstrap notify显示保存功能。问题是,用户可以保存多个。
示例:用户每秒都单击一次按钮(Checkbox1,Checkbox2等)。每个复选框都会调用notify函数。
目标:对话框应显示3秒钟。如果在3秒钟内再次单击该按钮,则不会再出现任何对话框。 3秒,但应从头开始(重新触发)
$(function(){
$(".btn").on("click",function(){
$.notify({
title: 'This dialog should appear only once',
icon: 'glyphicon glyphicon-star',
message: ""
},{
type: 'info',
animate: {
enter: 'animated fadeInUp',
exit: 'animated fadeOutRight'
},
placement: {
from: "bottom",
align: "left"
},
offset: 20,
spacing: 10,
z_index: 1031,
timer: 3000,
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mouse0270-bootstrap-notify/3.1.5/bootstrap-notify.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.3/animate.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<button class="btn btn-primary">click me</button>
答案 0 :(得分:1)
您可以使用 onClosed 事件,该事件在通知结束时通知您,当打开通知时,您可以阻止带有标志的再次打开,您可以在onClosed事件为被解雇了...
$(function(){
var busy = false;
$(".btn").on("click",function(){
if(!busy) {
busy=true;
$.notify({
title: 'This dialog should appear only once',
icon: 'glyphicon glyphicon-star',
message: ""
},{
type: 'info',
animate: {
enter: 'animated fadeInUp',
exit: 'animated fadeOutRight'
},
placement: {
from: "bottom",
align: "left"
},
offset: 20,
spacing: 10,
z_index: 1031,
timer: 3000,
onClosed: function() {
busy=false;
}
});
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mouse0270-bootstrap-notify/3.1.5/bootstrap-notify.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.3/animate.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<button class="btn btn-primary">click me</button>