Here is my HTML, CSS, JS
const Col = document.querySelectorAll('.col')
function onCol() {
Col.forEach(function(el, idx) {
el.style.transition = '0s';
el.style.height = '0%';
el.style.transition = '0.9s';
el.style.height = '100%';
});
}
onCol()
.work {
display: flex;
height: 140px
}
.col {
background: red;
width: 20px;
height: 100%;
margin-left: 5px;
max-height: 0
}
<div class="work">
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
<div class="col"></div>
</div>
I think that columns should become bigger SMOOTHLY WITH TRANSITION 0.9 !!!
but they do not.
If I type the word with el.style.height = '100%'; into setTimeOut, it will work.
but I don't want to make this in callback queue. I just want to solve this in the call stack.
and I want to know why doesn't this work now.
i changed this with for loop. but not works
setTimeout()allows there to be a pause/break in the JavaScript execution and allows the DOM/CSS to update.setTimeoutjust make the code (somewhat) asynchronous so that other things can be processed on the page's single thread. So no matter what there has to be some sort of pause/delay in the JavaScript if you want to actually see the change, andsetTimeoutis probably the simplest way to do that.requestAnimationFrameif you prefer, but ultimately, it's the same thing that @EssXTee is talking about, making the change occur at another time.transitionis a property that should be set once, since it tells the browser how long future changes should take. Then change theheightonce and the browser will animate between the two states. I think you'd be better off adding the states to CSS classes, then toggle the classes.