jquery - 如何在关闭模式时在 Sweet Alert 2 中应用动画?

标签 jquery html css ajax sweetalert2

有谁知道如何在甜蜜警报2关闭时应用动画?看起来function(dismiss)似乎没有达到目的。

$.ajax({
  method:'POST',
  url:'sql/record.php',
  data:formData,
  contentType: false,
  processData: false,
  success: function(response){
    swal({
      title: 'Success!',
      text: "New record has successfully added.",
      type: 'success',
      animation: false,
      customClass: 'animated tada',
      showCancelButton: false,
      confirmButtonText: 'OK'
    }).then(function(result){
    }, function(dismiss){
      swal({customClass: 'animated bounceOut'});
    }
  });
);

最佳答案

我知道这是一个老问题,但也许有人仍在寻找答案(就像我一样)。

我成功地将动画应用于关闭和确认 swal2。此方法不适用于单击 swal 外部以将其关闭。

swal({
    title: 'swal title',
    html: 'some content',
    showLoaderOnConfirm: true,
    animation: false,
    customClass: "animated fadeInLeft",
    onClose: function(){
        return delaySwalWithAnimation("fadeInLeft","fadeOutRight");
    },
    preConfirm: function(){
        return delaySwalWithAnimation("fadeInLeft","fadeOutRight");
    }
}).then(function(result) {
    //...
}

function delaySwalWithAnimation(animationToRemove, animationToAdd){
    return new Promise(function(resolve) {
        $(".swal2-popup").removeClass(animationToRemove);
        $(".swal2-popup").addClass(animationToAdd);
        setTimeout(function() {
            resolve();
        },300);
    });
}

关于jquery - 如何在关闭模式时在 Sweet Alert 2 中应用动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45808310/

相关文章:

javascript - 对对象数组和对象 Div 使用过滤器

css - CSS 编辑器中选择的 Visual Studio 格式不起作用

jquery - 当子菜单项处于事件状态并保持子菜单打开时,使用 jquery 突出显示父级

jquery - 在哪里编写 Bower 代码来安装 Alertify?

javascript - 简单的 jQuery 模态窗口在页面加载时不显示弹出窗口

javascript - 字体大小问题

javascript - rails 4 : custom action to update only one param with AJAX

jquery - 使用 Jquery 一次显示一个隐藏和显示部分

css - 使某些内容转到页面中的下一行的 CSS 是什么?

css - Primefaces IE p :tree not expanding