我正在尝试延迟 SweetAlert 弹出窗口,使其在触发后几秒钟不显示。
例如用户在网页上执行操作触发 SweetAlert,但不是立即显示,而是等待 2 秒然后显示。 - 我一直在研究各种方法来做到这一点,但没有运气......我想也许需要 setTimeout
?
这是我目前正在运行的 SweetAlert 函数:
if( response == 10 ){
swal({
type: 'success',
title: 'YOUR BALANCED BOX IS FULL',
text: 'Youve added the recommended amount of items for your plan!',
allowOutsideClick: false,
showCancelButton: true,
cancelButtonText: "Modify Selection",
cancelButtonColor: '#d33',
showConfirmButton: true,
confirmButtonColor: '#61ce70',
confirmButtonText: "Proceed To Cart",
}).then((result) => {
if (result.value) {
window.location = "/basket/";
}
})
}
感谢任何帮助!
最佳答案
特定的 SWEETALERT 2 答案:
Leo 的上述代码逻辑答案是正确的。我与 SweetAlert 2 共享最终版本,其中添加了 setTimeout
功能以延迟打开弹出窗口。
setTimeout
函数环绕整个 SweetAlert 2 函数,定时器设置在函数末尾的底部(在本例中为 3000)。
希望这对任何想做同样事情的人有所帮助!
setTimeout(function(){swal({
type: 'success',
title: 'YOUR BALANCED BOX IS FULL',
text: 'Youve added the recommended amount of items for your plan!',
allowOutsideClick: false,
showCancelButton: true,
cancelButtonText: "Modify Selection",
cancelButtonColor: '#d33',
showConfirmButton: true,
confirmButtonColor: '#61ce70',
confirmButtonText: "Proceed To Cart",
}).then((result) => {
if (result.value) {
window.location = "/basket/";
}
})},3000);
关于javascript - Sweetalert 延迟弹出窗口打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51794373/