Within my HTML code, I have defined a toast element:
<div class="position-fixed top-0 start-50 translate-middle-x" style="z-index: 9999">
<div id="errNeutralAlreadyExists" class="toast fade bg-solid-white"
role="alert" aria-live="assertive" aria-atomic="true"
data-bs-animation="true" data-bs-autohide="true" data-bs-delay="3000">
<div class="toast-header">
<strong class="me-auto js-toast-title">Toast Title</strong>
</div>
<div class="toast-body">
Content of the toast message will go here
</div>
</div>
</div>
Although the toast works correctly, I am looking to make it disappear slowly rather than abruptly vanishing. I attempted to assign a class for this purpose, but it doesn't seem to have the desired effect:
.toast.hide {
transition-duration: 1s;
}
How can I achieve a slow, graceful disappearance for the toast message?
const toastTrigger = document.getElementById('liveToastBtn')
const toastLiveExample = document.getElementById('errNeutralAlreadyExists')
if (toastTrigger) {
toastTrigger.addEventListener('click', () => {
const toast = new bootstrap.Toast(toastLiveExample)
toast.show()
})
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9cbc6c6dddeddcbc7dbcdce8bd4dbcb97c0c8cf">[email protected]</a>/dist/css/bootstrap.min.css" integrity="sha384-jr2vpqO2s2g5zhTbs42g3h7to3Yk3gluFLjQ/KW2Fg6uyKiw2VV7rgVKd5vva" crossorigin="anonymous">
<button type="button" class="btn btn-primary" id="liveToastBtn">Display live toast</button>
<div class="position-fixed top-0 start-50 translate-middle-x" style="z-index: 9999">
<div id="errNeutralAlreadyExists" class="toast fade bg-solid-white" role="alert" aria-live="assertive" aria-atomic="true" data-bs-animation="true" data-bs-autohide="true" data-bs-delay="3000">
<div class="toast-header">
<strong class="me-auto js-toast-title">Toast Title</strong>
</div>
<div class="toast-body">
Content of the toast message will go here
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="086a67677c6f6f6d6e69505164f3517e636a6e656b54655a61">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-18ZIxfFwWswrEKLCT6TONNyN9qGuxBmCuKd+rcKOfLjeSMUTF/tA1giqDkcN9" crossorigin="anonymous"></script>