最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Sweetalert2 : correct way to completely disable animation with version >= 9.0.0 - Stack Overflow

programmeradmin3浏览0评论

Before version 9.0.0 i used this code to completely disable animation on a toast alert.

Swal.fire({
    animation : false,
    toast: true,
    ....
});

Now with version 9.* i tried with this code, and the result it looks the same

Swal.fire({
    showClass : { popup : "swal2-noanimation", backdrop : "swal2-noanimation", icon : "swal2-noanimation"},
    //hideClass : { popup : "swal2-noanimation", backdrop : "swal2-noanimation", icon : "swal2-noanimation"},
    toast: true,
    ....
});

If i enable also the property hideClass i can't hide the alert with the method Swal.close().

So what is the correct solution to get the same effect as before?

Before version 9.0.0 i used this code to completely disable animation on a toast alert.

Swal.fire({
    animation : false,
    toast: true,
    ....
});

Now with version 9.* i tried with this code, and the result it looks the same

Swal.fire({
    showClass : { popup : "swal2-noanimation", backdrop : "swal2-noanimation", icon : "swal2-noanimation"},
    //hideClass : { popup : "swal2-noanimation", backdrop : "swal2-noanimation", icon : "swal2-noanimation"},
    toast: true,
    ....
});

If i enable also the property hideClass i can't hide the alert with the method Swal.close().

So what is the correct solution to get the same effect as before?

Share Improve this question edited May 16, 2021 at 13:06 Melvin 1,0411 gold badge11 silver badges25 bronze badges asked Nov 8, 2019 at 9:59 WhiteLineWhiteLine 1,9912 gold badges25 silver badges53 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 23

Starting from v11.10.0 the animation parameter was re-introduced:

Swal.fire({
  ...
  animation: false
})

⚠ OUTDATED ANSWER BELOW: ⚠

As per deprection message:

SweetAlert2: "animation" is deprecated and will be removed in the next major release. Please use "showClass" and "hideClass" instead.

Swal.fire({
  icon: 'success',
  title: 'I am not animated',
  showClass: {
    backdrop: 'swal2-noanimation', // disable backdrop animation
    popup: '',                     // disable popup animation
    icon: ''                       // disable icon animation
  },
  hideClass: {
    popup: '',                     // disable popup fade-out animation
  },
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

Read the release notes to see all breaking changes: https://github.com/sweetalert2/sweetalert2/releases/tag/v9.0.0

发布评论

评论列表(0)

  1. 暂无评论