<div class="animated"></div>
<button>Set div width 100px</button>
div {
width: 50px;
height: 50px;
background: red;
}
.animated {
animation: mymove .5s ease forwards;
}
@keyframes mymove {
from {width: 50px;}
to {width: 200px;}
}
document.querySelector('button').addEventListener('click', () => {
const div = document.querySelector('div');
div.classList.remove('animated');
// comment 👆 line and 👇 line will no affect
div.style.width = '100px';
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.