这是小提琴:Fiddle
注释掉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
},
});
然后我在按钮上有一个点击事件来激活“jello”效果:
$('#clickMeButton').on('click', function() {
// if animate above is commented out, this works, otherwise
// this does not work
notification.attention('jello');
});
我需要同时使用这两种效果,当通知出现时它必须以此效果反弹,点击它时必须做'jello'效果,当隐藏/关闭它时必须反弹效果。
答案 0 :(得分: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');
});