Here the transition works just fine. But if I don't use setTimeout and straightforwardly make the transform the div is already at the end of transition.
function move(x, y, delay) {
let el = document.getElementById('myDiv');
el.style.transform = `translateX(${x}%)`
el.style.transition = `transform ${delay}s linear`
setTimeout(() => {
el.style.transform = `translateX(${y}%)`
}, 1000)
}
move(100, 200, 1)
.myDiv {
height: 50px;
width: 50px;
background: blue;
}
<div class="myDiv" id="myDiv">
Content
</div>
In This case div is already at the end of transition. But js being synchronous all these instructions should be executed sequentially then why the entire transition is not taking place in this case?
function move(x, y, delay) {
let el = document.getElementById('myDiv');
el.style.transform = `translateX(${x}%)`
el.style.transition = `transform ${delay}s linear`
el.style.transform = `translateX(${y}%)`
}
move(100, 200, 1)
.myDiv {
height: 50px;
width: 50px;
background: blue;
}
<div class="myDiv" id="myDiv">
Content
</div>