Show with animation the content added with JavaScript
Posted: 17 Nov 2020, 11:44
The idea is that when i click on a button, old content gets replaced by new HTML content added with javascript.
I want that new content to appear with animation; to fade in from the right (a css transition) every time i click the button.
Here is a snippet of what i have in mind, but I don't know how to add with animation (the transition):
I want that new content to appear with animation; to fade in from the right (a css transition) every time i click the button.
Here is a snippet of what i have in mind, but I don't know how to add with animation (the transition):
Code: Select all
<style>
#pag_cnt p {
font-size: 40px;
}
</style>
<div id='pag_cnt'>
<p>Hello world!</p>
</div>
<button onclick='add_anim()'>Click here</button>
<script>
let new_cnt = `<p>It's me again!</p>`;
function add_anim() {
let pag_cnt = document.getElementById('pag_cnt');
pag_cnt.innerHTML = new_cnt;
}
</script>