I update the content of a div with a JavaScript function and i want to trigger animation on the div each time a new mailbox is loaded.
But the animation get triggered once on reload or when i'm switched back from another div .
Notice that i'm switching beetween divsby tweaking the displayattribute of each div.
document.addEventListener('DOMContentLoaded', function() {
// Use buttons to toggle between views
document.querySelector('#inbox').addEventListener('click', () => load_mailbox('inbox'));
document.querySelector('#sent').addEventListener('click', () => load_mailbox('sent'));
document.querySelector('#archived').addEventListener('click', () => load_mailbox('archive'));
// By default, load the inbox
load_mailbox('inbox');
}
function load_mailbox(mailbox) {
// Show the mailbox and hide other views
document.querySelector('#emails-view').style.display = 'block';
document.querySelector('#mail-view').style.display = 'none';
document.querySelector('#compose-view').style.display = 'none';
// Show the mailbox name
document.querySelector('#emails-view').innerHTML = `<h3>${mailbox.charAt(0).toUpperCase() + mailbox.slice(1)} </h3>`;
}
I wrote the animation and link the div to it expecting the animation will load on each function call but instead of that the animation loads on reach refresh of the page.
#emails-view {
position: relative;
background-color: transparent;
text-align: center;
font-size: 20px;
background-color:white;
width: 100%;
padding-bottom: 10px;
border-radius: 15px;
}
@keyframes grow {
0% { top: 0%;
}
30% {top: 50%;
}
100% {top: 0%;
}
}
#emails-view {
animation-name: grow;
animation-duration: 1s;
animation-fill-mode: forwards;
}
The HTML is that :
<hr>
<div id="emails-view">
</div>
<div id="mail-view" class="card">
<div id="mail-header" class="card-header">
<div style="font-weight:bold;" id='mail-sender'></div>
<div style="font-weight:bold;" id='mail-receiver'></div>
</div>
<div id="card-body-1" class="card-body">
<h5 style="font-weight:bold;" id="mail-subject" class="card-title"></h5>
<p id="mail-time" class="card-text"></p>
<a id="mail-button-reply" href="#" class="btn btn-primary">reply</a>
<a id="mail-button-archive" href="#" class="btn btn-secondary">Archive</a>
</div>
<div id="card-body-2" class="card-body">
<p style="font-size: 20px;" id="mail-content" class="card-text"></p>
</div>
</div>
<div id="compose-view">
<h3>New Email</h3>
<form id="compose-form">
<div class="form-group">
From: <input disabled class="form-control" value="{{ request.user.email }}">
</div>
<div class="form-group">
To: <input id="compose-recipients" class="form-control">
</div>
<div class="form-group">
<input style="font: bold; font-size: 30px;" class="form-control" id="compose-subject" placeholder="Subject">
</div>
<textarea style="font-size: 20px;" class="form-control" id="compose-body" placeholder="Body"></textarea>
<input style="color: white;" id='compose-submit' type="submit" class="btn btn-primary" value="Send Mail"/>
</form>
</div>
document.getElementById("myelement").classList.remove("mystyle");anddocument.getElementById("myelement").classList.add("mystyle");load_mailboxfunction sets the display of#email-viewtoblock, but nothing's setting it tononeor anything else. So why do you expect the animation to re-trigger?#email-viewby passing a differentmailboxto theload_mailbox<div id="emails-view"> </div>