1

这是小提琴:小提琴

注释掉该animate: {}部分,然后单击按钮以查看没有它的“jello”动画是否有效,初始加载动画有效但 jello 无效。

我正在使用PNotify插件。这是我的设置:

PNotify.prototype.options.styling = "jqueryui";
var myStack = {"dir1":"down", "dir2":"left", "push":"top"};

var notification = new PNotify({
   title: "Test Title",
   text: "Test Content",
   stack: myStack,
   icon: 'glyphicon glyphicon-info-sign',
   type: 'info',
   // IF I COMMENT THIS OUT, THE "jello" effect works fine but then
   // when showing/hiding the notification it does not use the bellow effects
   animate: {
        animate: true,
        in_class: 'bounceInDown',
        out_class: 'bounceOutUp'
    },
    buttons: {
        sticker: false,
        closer_hover: false
    },
    mobile: {
        swipe_dismiss: true,
        styling: true
    },
    nonblock: {
        nonblock: false,
        nonblock_opacity: .2
    },
});

然后我在按钮上有一个点击事件来激活“果冻”效果:

$('#clickMeButton').on('click', function() {
    // if animate above is commented out, this works, otherwise
    // this does not work
    notification.attention('jello');
});

我需要这两种效果才能工作,当通知显示时它必须以该效果反弹,当点击它必须做“果冻”效果时,当隐藏/关闭它时它必须做反弹效果。

4

1 回答 1

1

这有效

    $('#clickMeButton').on('click', function() {
        notification.get().removeClass('animated bounceInDown bounceOutUp');
        notification.attention('jello');
});

需要首先删除该类,这在 PNotify 库的意图函数中没有完成。

notice.attention = function(aniClass, callback){
            notice.elem.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
                notice.elem.removeClass(aniClass);
                if (callback) {
                    callback.call(notice);
                }
            }).addClass("animated "+aniClass);

您可以更改 PNotify 库的代码,这将更便于将来使用其他动画预设。对上述原始代码的一些更改如下。只需添加我在评论中提到的行。

notice.attention = function(aniClass, callback){
            //just add the line below
            notice.elem.removeClass(this.options.animate.in_class + " " + this.options.animate.out_class);
            notice.elem.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
                notice.elem.removeClass(aniClass);
                if (callback) {
                    callback.call(notice);
                }
            }).addClass("animated "+aniClass);
        };

您现在可以立即调用注意功能

$('#clickMeButton').on('click', function() {
            notification.attention('jello');
    });
于 2016-09-22T13:27:42.780 回答