当前我们正在使用jQuery noty,该jQuery Noty在5秒钟后自动关闭。但是我们也希望如果任何用户在屏幕上的任何地方都可以在这种情况下关闭。
。在这种情况下,任何人都可以帮助我。
以下是在屏幕上获取noty的代码
var objnoty = noty({
// Text Shown on Error
text: '<div class="Close" onclick="closeNoty(this)"></div><div> <div class="Main_Err">' + errorMainText + '</div><div class="LineGap"></div><div class="Subhead">' + errorSubText + '</div></div> ',
// Property used to define Error Layout Shown.
layout: 'topRight',
// Type of Noty
type: 'error',
// Theme used.
theme: 'defaultTheme',
killer: true,
maxVisible: 1,
// Basic Animations
animation: {
open: { height: 'toggle' }, // or Animate.css class names like: 'animated bounceInLeft'
close: { height: 'toggle' }, // or Animate.css class names like: 'animated bounceOutLeft'
easing: 'swing',
speed: 500 // opening & closing animation speed
},
// ['click', 'button', 'hover', 'backdrop'] // backdrop click will close all notifications
closeWith: [],
// Used to set the time out of noty.
timeout: 500,
// Call back events
callback: {
// function is called before noty is shown
// It is used to set the noty count to open again one noty
onShow: function () {
var panel = GetCtlObject('dvPersonalDataContainer');
var collapseButton = $(panel).find('.panel-collapsebutton-image');
if (collapseButton.length > 0) {
changePanelState($(panel).find('.panel-expandbutton'), null);
}
setTimeout(function () { setFocusOnFirstErrControl(); }, 80);
setValue(Control.HDNotyCount, TSIConstants.One);
setRightPostion();
},
// function is called on close on noty.
// It is used to reset the noty count and enable noty visibilty.
onClose: function () {
setValue(Control.HDNotyCount, TSIConstants.Zero);
jsonObjectList = [];
},
// function called after noty is shown.
// It is used to set the timer to close the noty again.
afterShow: function () {
var that = this;
setTimeout(function () {
setValue(Control.HDNotyCount, TSIConstants.Two);
jsonObjectList = [];
}, 0);
$($('.noty_text').parent().parent()).mouseenter(function () {
focus = 0;
clearTimeout(NotyHideTime);
});
$($('.noty_text').parent().parent()).mouseleave(function () {
focus = 1;
that.setTimeout(5000);
});
NotyHideTime = that.setTimeout(5000);
},
},
// Button used to close noty
buttons: [
{
addClass: 'btn btn-primary', text: 'Ok', onClick: function ($noty) {
$noty.close();
}
}
]
});
}
我可以通过单击不在noty上的按钮关闭。
set modal:true 显示具有模态背景的通知,例如:
new Noty({
text: 'your message',
type: 'error',
dismissQueue: false,
layout: 'center',
modal: true
}).show();
然后,您将能够捕获模态背景点击即可关闭通知:
$(document).on('click', '.noty_modal', function(){
$('.noty_bar').click();
});