如何在任何点击窗口的地方关闭noty

时间:2017-09-05 10:19:19

标签: javascript jquery asp.net-mvc 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();

                        }
                    }
        ]
    });
}

我可以使用按钮点击关闭相同的内容吗。

1 个答案:

答案 0 :(得分:0)

设置 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();
});