Skip to content

Instantly share code, notes, and snippets.

@MichaelDeMattos
Last active August 12, 2022 14:12
Show Gist options
  • Save MichaelDeMattos/0db13ed754c9a22f9cfc68428d13bfd6 to your computer and use it in GitHub Desktop.
Save MichaelDeMattos/0db13ed754c9a22f9cfc68428d13bfd6 to your computer and use it in GitHub Desktop.
How to use modal with progress using Sweetalet2, JavaScript, Jquery and HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script>
</head>
<body>
<button id="btn_submit">Click Here!</button>
<script>
// On submit show modal progress Using Sweetalert2
$("#btn_submit").on("click", async function (e) {
try {
let progress = Swal.fire({
title: 'Closing in 5 seconds!',
didOpen: () => { Swal.showLoading() },
});
// Your code here
setInterval(() => {
progress.close();
}, 5000);
} catch (error) {
console.log(String(error));
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment