Created
October 7, 2024 07:42
-
-
Save erdum/ce33f57ca7d10f5d200f2b468e6780e3 to your computer and use it in GitHub Desktop.
Simple Toast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="toast" class="hidden"> | |
<span id="toast-message">Success message</span> | |
</div> | |
<script> | |
function showToast(message, type = 'success') { | |
const toast = document.getElementById('toast'); | |
const toastMessage = document.getElementById('toast-message'); | |
toastMessage.textContent = message; | |
toast.className = `fixed hidden scale-0 transition bottom-6 right-6 py-4 px-8 rounded shadow-md text-white font-semibold z-50 ${type === 'success' ? 'bg-green-600' : 'bg-red-600'}`; | |
setTimeout(() => { | |
toast.classList.remove('hidden'); | |
setTimeout(() => { | |
toast.classList.remove('scale-0'); | |
toast.classList.add('scale-100'); | |
}, 10); | |
}, 10); | |
setTimeout(() => { | |
toast.classList.remove('scale-100'); | |
toast.classList.add('scale-0'); | |
setTimeout(() => { | |
toast.classList.add('hidden'); | |
}, 250); | |
}, 3000); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment