javascript - 如何更改 SweetAlert2 的关闭动画?

标签 javascript sweetalert2

我正在使用 SweetAlert2 v8 和 animate.css 来更改弹出动画。我使用的动画是fadeInRight。我也在使用链式警报,并希望将关闭动画更改为 fadeOutLeft 以使其在页面上滑动。

我添加 animate.css 类的方式是使用 customClass 弹出属性。

我试过了:

  • 使用 onClose 添加类
  • 使用onOpen 删除fadeIn 类,然后使用onClose 添加fadeOut 类

  • 这两种方法似乎都不起作用。如果有人知道如何更改结束动画,将不胜感激。

    谢谢

    最佳答案

    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(animationA, animationB){
        return new Promise(function(resolve) {
            $(".swal2-popup").removeClass(animationA);
            $(".swal2-popup").addClass(animationB);
            setTimeout(function() {
                resolve();
            },300);
        });
    }
    

    关于javascript - 如何更改 SweetAlert2 的关闭动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57341949/

    相关文章:

    javascript - 我如何使用 JavaScript 将结果与其他文本一起使用

    javascript - Vue.js,如何从组件中填充 SweetAlert2 html 表单数据

    angular - 如何更改 Angular 中甜蜜警报的文本属性?

    javascript - SweetAlert2 确认对话框在 onclick 中无法正常工作

    javascript - 将 SweetAlert2 与 Angular 一起使用时如何保持范围?

    javascript - Django 模板 - 会计格式的 Bootstrap 表编号

    javascript - HTML5音频-所有网页的音乐相同

    javascript - 碰撞检测p5.js

    javascript - 为什么这个 Facebook javascript-sdk 登录代码会一次又一次自动登录用户?

    javascript - 尝试使用函数组合时出现 ReferenceError : error is not defined,