It is possible to stop an insertBefore, inside an addEventListener, to add a smooth css, so that the movement produced by the insertion of the div is not abrupt for the user?
I have read many questions, i have tried using settimeout in various ways, without success:
const gallery = document.getElementById('gallery');
const frames = gallery.querySelectorAll('.frame');
for (var i = 0; i < frames.length; ++i) {
frames[i].addEventListener('click', function() {
if (this.className == "frame b") {
//setTimeout( function(){
gallery.insertBefore(this, this.previousElementSibling);
//}, 1000 );
} else {
//setTimeout( function(){
gallery.insertBefore(this, this.previousElementSibling);
//}, 1000 );
};
});
};
.frame {
width: 200px;
height: 100px;
font: bold 400% sans-serif;
color: white;
float: left;
}
.frame.a {
background-color: brown;
}
.frame.b {
background-color: purple;
}
<div id="gallery">
<div class="frame a">A</div>
<div class="frame b">B</div>
</div>