I have successfully implemented code that removes a div and animates the content inside to create a sliding effect. However, I am facing an issue where the divs below seem to jump up and I am looking for a way to make this transition smoother. Here is the code snippet I am using:
$(document).on('click', 'div', function() {
const span = $(this).find('span');
const div = $(this);
span.css({
'right': '100%'
});
window.setTimeout(function() {
div.hide();
}, 250);
})
div {
width: 100%;
height: 5em;
text-align: center;
vertical-align: middle;
padding: 20px;
background-color: #e6e6e6;
margin-bottom: 10px;
}
div>span {
right: 50%;
display: block;
position: absolute;
transition: all 0.25s ease-out;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<div>
<span>
one
</span>
</div>
<div>
<span>
two
</span>
</div>
<div>
<span>
three
</span>
</div>
<div>
<span>
four
</span>
</div>