I am creating a system to upload images with drag and drop, the idea is that each image is added by appearing in a grid, I use promises so that the image only appears when it is already loaded with the onload event, but not I get it to appear with a smooth transition. I leave a simple example of the problem
let cont = document.getElementById('container')
let btn = document.getElementById('addEl')
btn.addEventListener('click',function(){
let newEl = document.createElement('div')
newEl.classList.add('elemento')
cont.appendChild(newEl)
newEl.classList.add('visible')
})
#container {
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
width: 100%;
height: 300px;
background-color: tomato;
}
.elemento {
width: 50px;
height: 50px;
background-color: #1a1a1a;
opacity: 0;
transition: opacity 2s ease.in;
}
.visible {
opacity: 1;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
</div>
<button type="button" id="addEl">Agregar Elemento</button>
As much as possible, I prefer not to use libraries.