7

メッセージのリストを入力すると、Jquery noty プラグインのタイムアウトが機能しません。サーブレットからメッセージの一覧を取得し、このように noty を呼び出します。

<script>
    function callNotification()
    {
        <c:foreach var = "message" items = "${sessionScope.notification}">
             notify('${message}');
        </c:foreach>
    }
    function notify(message)
    {
       noty({
                "text": message,
                "theme": noty_theme_facebook",
                "layout": topRight,
                "information","animateOpen":{"height":"toggle"},
                "information","animateOpen":{"height":"toggle"},
                "speed":500,
                "timeout":5000,
                "closeButton":true,
                "closeOnSelfClick":true,
                "closeOnSelfOver":false,
                "modal":false
          })
    </script>

理想的には、これはメッセージをループし、5000 ミリ秒のタイムアウトでメッセージを出力する必要があります。しかし、これは一度にすべてのメッセージを出力します。さらに、javascript ネイティブの setTimeout 関数を使用して、callNotification をこれに置き換えました。

 function callNotification()
    {
        <c:foreach var = "message" items = "${sessionScope.notification}">
         (function(message){ 
            setTimeout(function(){notify('${message}');},5000)
         }('${message}')
        }}
        </c:foreach>
    }

しかし、これも効果がないことが判明しました。奇妙なことに"layout":center、notify メソッドを置き換えると、タイムアウトが正常に機能するようです。どこが間違っているのですか。最初のメッセージが自動的に消去され、次のメッセージが表示された後、5 秒のタイムアウトでメッセージを表示したい。

4

7 に答える 7

3

これを機能させるために、jquery.noty.js で次のように変更しました ...

self.$bar.delay(self.options.timeout).promise().done(function () {
                self.close();
            });

これに...

setTimeout(function () {
                self.close();
            }, self.options.timeout);
于 2013-07-11T19:28:46.327 に答える
2

タイムアウトオプションを試してみcloseWithて、うまくいくことを願っています

   function generate(type, text) {

                var n = noty({
                    text        : text,
                    type        : type,
                    dismissQueue: true,
                    layout      : 'topRight',
                    closeWith   : ['click','timeout'],
                    theme       : 'relax',
                    maxVisible  : 10,
                    timeout     :7000,

                    animation   : {
                        open  : 'animated bounceInRight',
                        close : 'animated bounceOutRight',
                        easing: 'swing',
                        speed : 500
                    }
                });
于 2016-02-24T12:27:39.803 に答える
0

jquery.noty.packaged.js で、「master_self」ファイルという名前のグローバル変数を作成します。103 行目または 104 行目で、 var self = this;その行のすぐ下に master_self を self として割り当てる行が必要です。master_self = self;

同じファイルに関数を作成します。

function autoTimeout(timeoutVal){
    setTimeout(function(){
                            var self = master_self;
                            if (typeof self.options.animation.close == 'string') {
                                self.$bar.addClass(self.options.animation.close).one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
                                    if(self.options.callback.afterClose) self.options.callback.afterClose.apply(self);
                                    console.log(self);
                                    self.closeCleanUp();
                                });
                            } else {
                                self.$bar.clearQueue().stop().animate(
                                    self.options.animation.close,
                                    self.options.animation.speed,
                                    self.options.animation.easing,
                                    function() {
                                        if(self.options.callback.afterClose) self.options.callback.afterClose.apply(self);
                                    })
                                    .promise().done(function() {
                                        self.closeCleanUp();
                                    });
                            }
                         },timeoutVal);
}

通知を作成するために noty オブジェクトを呼び出した直後に、この方法でタイムアウトする通知でこの関数を明示的に呼び出します。

autoTimeout(1000);
于 2015-09-08T10:54:20.450 に答える
0

このオプションをパラメータとして指定する必要があります: "buttons: false"

于 2015-03-31T06:59:00.620 に答える