Jquery 关闭模式时,如何在sweet alert 2中应用动画?
有人知道如何在关闭时将动画应用于sweet alert 2吗?看来Jquery 关闭模式时,如何在sweet alert 2中应用动画?,jquery,html,css,ajax,sweetalert2,Jquery,Html,Css,Ajax,Sweetalert2,有人知道如何在关闭时将动画应用于sweet alert 2吗?看来函数(dismise)似乎不起作用 $.ajax({ method:'POST', url:'sql/record.php', data:formData, contentType: false, processData: false, success: function(response){ swal({ title: 'Success!', text: "New reco
函数(dismise)
似乎不起作用
$.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'});
}
});
);
您应该添加一个名为
onClose
的属性。试试这个:
$.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',
onClose: function(modal) {
modal.className += ' 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);
});
}
这看起来很有希望,但不幸的是,我无法让它工作,因为当按下关闭按钮时,在事件触发之前,模式会立即关闭。你知道怎么解决这个问题吗?我考虑制作一个自定义关闭按钮,但如果有一个更简单的方法,将不胜感激。