autoclose alert messages after 5 seconds
All checks were successful
Build and Deploy Staging / build (push) Successful in 1m2s
Tests / test (push) Successful in 25s
Build and Deploy Staging / deploy (push) Successful in 8s

This commit is contained in:
Tobias Brunner 2025-07-07 11:37:02 +02:00
parent 60d550a7bf
commit d11d48ad5c
No known key found for this signature in database

View file

@ -1,7 +1,28 @@
<div class="alert alert-{{ message.tags }} alert-dismissible"> <div class="alert alert-{{ message.tags }} alert-dismissible" id="auto-dismiss-alert-{{ forloop.counter0|default:'0' }}">
{{ message }} {{ message }}
<button type="button" <button type="button"
class="btn-close" class="btn-close"
data-bs-dismiss="alert" data-bs-dismiss="alert"
aria-label="Close"></button> aria-label="Close"></button>
</div> </div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const alert = document.getElementById('auto-dismiss-alert-{{ forloop.counter0|default:'0' }}');
if (alert) {
setTimeout(function() {
let opacity = 1;
const fadeOutInterval = setInterval(function() {
if (opacity > 0.05) {
opacity -= 0.05;
alert.style.opacity = opacity;
} else {
clearInterval(fadeOutInterval);
const bsAlert = new bootstrap.Alert(alert);
bsAlert.close();
}
}, 25);
}, 5000);
}
});
</script>