I want to display a loading sweet alert while a loop is running. How can I make that possible. What currently happens is the sweet alert only opens for a split second after the loop has finished. I have tried making testFunc async and awaiting the wait function, but that didn't help. Not sure what to do at this point. I appreciate any help. Thank you so much
function wait(ms) {
var start = new Date().getTime();
var end = start;
while (end < start + ms) {
end = new Date().getTime();
}
}
function testFunc() {
sweetAlert({
title: "Please wait",
showCancelButton: false,
showConfirmButton: false,
});
wait(3000);
console.log("done");
sweetAlert.close();
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.0/sweetalert.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.0/sweetalert.min.js"></script>
<button id="testBtn" onclick="testFunc()">TEST</button>
Comments
Post a Comment