javascript - Sweetalert延迟弹出窗口
问题描述
我正在尝试延迟 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
添加了一项功能以延迟弹出窗口的打开。
The setTimeout
function wraps around the entire SweetAlert 2 function and the timer is set at the bottom of the end of the function (in this case to 3000).
Hope this helps anyone looking to do the same!
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 - 导入模块 NodeJS 中的所有导出
- sql - 基于 2 列组合条件在表中插入缺失值的 T-SQL 查询
- python - 无法在 PDT 时区获取当前时间戳
- vb.net - Linq to Entities,选择有子实体的父实体,子实体匹配条件
- swift - 是否可以在约束中包含 Core Data 实体类型?
- windows - 我最新的 Windows 10 SDK 安装不包括 rc.exe 和 rcdll.exe,所以我收到 LNK1158 错误
- networking - 将 Kong Admin API 暴露给内部网络
- c++ - 将 QVector 缩小到最后 10 个元素并重新排列一项
- reactjs - Icomoon:删除 icomoon.ttf 后 Xcode 构建失败,仍然正常运行
- mysql - Hibernate 没有从 MySQL 数据库中检索到给定日期的正确行