Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sweetalert2 : correct way to completely disable animation with version >= 9.0.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?

like image 319
WhiteLine Avatar asked Nov 08 '19 09:11

WhiteLine


1 Answers

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

like image 52
Limon Monte Avatar answered Nov 06 '22 13:11

Limon Monte