Vissza a webes elemekhez
Értesítések és panelek

(Eltűnő értesítés

Élő előnézet – a komponens teljes méretben.

Élő előnézet
HTML · CSS · JS
HTML
<div id="toast-success" class="flex items-center w-full max-w-xs p-4 text-gray-400 bg-gray-900 rounded-lg shadow border border-gray-800 fixed bottom-5 right-5 transform translate-y-0 opacity-100 transition-all duration-300" role="alert">
    <div class="inline-flex items-center justify-center flex-shrink-0 w-8 h-8 text-green-500 bg-green-900/20 rounded-lg">
        <svg class="w-5 h-5" aria-hidden="true" xmlns="http://w3.org" fill="currentColor" viewBox="0 0 20 20">
            <path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5Zm3.707 8.207-4 4a1 1 0 0 1-1.414 0l-2-2a1 1 0 0 1 1.414-1.414L9 10.586l3.293-3.293a1 1 0 0 1 1.414 1.414Z"/>
        </svg>
    </div>
    <div class="ms-3 text-sm font-normal">A változtatások sikeresen mentve!</div>
    <button type="button" id="close-toast" class="ms-auto -mx-1.5 -my-1.5 bg-transparent text-gray-500 hover:text-white rounded-lg p-1.5 inline-flex items-center justify-center h-8 w-8 hover:bg-gray-800" aria-label="Close">
        <svg class="w-3 h-3" aria-hidden="true" xmlns="http://w3.org" fill="none" viewBox="0 0 14 14">
            <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
        </svg>
    </button>
</div>
CSS
/* Ha nem Tailwindet használsz az animáció elrejtéséhez, ezzel finoman elhalványítható */
.toast-hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}
JavaScript
const toast = document.getElementById('toast-success');
const closeBtn = document.getElementById('close-toast');

// Manuális bezárás gombra kattintva
closeBtn.addEventListener('click', () => {
    hideToast();
});

// Automatikus eltűnés 4 másodperc után
setTimeout(() => {
    hideToast();
}, 4000);

function hideToast() {
    if(toast) {
        toast.classList.add('opacity-0', 'translate-y-2', 'pointer-events-none');
        // Opcionális: teljes eltávolítás a DOM-ból az animáció lefutása után
        setTimeout(() => toast.remove(), 300);
    }
}