Performance: Toast notifications
MEDIUM IMPACT
Toast notifications affect interaction responsiveness and visual stability by adding transient UI elements that appear and disappear dynamically.
<div id="toast" class="toast" role="alert" aria-live="assertive" aria-atomic="true"></div> <script> function showToast(message) { const toast = document.getElementById('toast'); toast.textContent = message; toast.classList.add('show'); setTimeout(() => { toast.classList.remove('show'); }, 3000); } </script> <style> .toast { position: fixed; bottom: 1rem; right: 1rem; opacity: 0; pointer-events: none; transition: opacity 0.3s ease-in-out; } .toast.show { opacity: 1; pointer-events: auto; } </style>
<div id="toast" style="display:none; position:fixed; bottom:0; width:100%; background:#000; color:#fff;" aria-live="polite"></div> <script> function showToast(message) { const toast = document.getElementById('toast'); toast.style.display = 'block'; toast.textContent = message; setTimeout(() => { toast.style.display = 'none'; }, 3000); } </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Toggle display property | 1 node updated | 2 reflows per show/hide | High paint cost due to layout shift | [X] Bad |
| Toggle opacity with CSS transitions | 1 node updated | 0 reflows | Low paint and composite cost | [OK] Good |