When attempting to create a smooth progress bar animation by adjusting the width using
document.querySelector('#mydiv').style.width = '20%'
, I noticed that the new width is updated instantly rather than transitioning smoothly. It seems like I may be overlooking something obvious or misunderstanding how the transition property works. Any advice on how to fix this issue would be greatly appreciated.
setTimeout(function() {
document.querySelector('#mydiv').style.width = '20%';
}, 500);
#mydiv {
position: absolute;
top: 0;
left: 0;
width: 0;
height: 0.4rem;
background: orange;
transition: width 1s ease-out;
}
<div id="mydiv"></div>