如何使 sweetAlert (swal) 表现得像常规 js 警报函数一样?
我试图在正在运行的游戏中的硬币数量为 20 时出现“sweetalert2”框。(我想让用户知道他们已经达到 20 个硬币)。如果我只是使用警报,则会出现警报框并且游戏暂停。但是,我想使用 sweetalert 框来获得更好的外观,但即使该框出现,游戏仍然继续运行。当出现 sweetalert 框时如何停止游戏?警报功能完美地处理了这个问题,但对于游戏来说就太简单了。 这是我的 sweetalert 代码:
swal({
allowOutsideClick: false,
title: 'You have 20 coins',
html:
'<input id="swal-input1" class="swal2-input">' +
'<input id="swal-input2" class="swal2-input">',
preConfirm: function () {
return new Promise(function (resolve) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val()
])
})
},
onOpen: function () {
$('#swal-input1').focus()
}
}).then(function (result) {
swal(JSON.stringify(result))
}).catch(swal.noop)
I am trying to make a "sweetalert2" box appear when the number of coins in a running game is 20. (I want to let the user know that they have reached 20 coins). If I just used alert, an alert box appears and the game pauses. However, I want to use the sweetalert box for better looks, but even when the box appears, the game still goes on running. How do I stop the game when the sweetalert box appears? The alert function handles this perfectly but it will be too plain for the game.
Here is the sweetalert code that I have:
swal({
allowOutsideClick: false,
title: 'You have 20 coins',
html:
'<input id="swal-input1" class="swal2-input">' +
'<input id="swal-input2" class="swal2-input">',
preConfirm: function () {
return new Promise(function (resolve) {
resolve([
$('#swal-input1').val(),
$('#swal-input2').val()
])
})
},
onOpen: function () {
$('#swal-input1').focus()
}
}).then(function (result) {
swal(JSON.stringify(result))
}).catch(swal.noop)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论