Tweening in CSS

Arnošt Neurad
Apr 23 · 4 min read
const forceBoxToPlayTransition = (before = () => null, after = () => null) => {
before();
// –––––––– this sequence creates a new transition start spot based on the element's current location/progress ––––––––––––
box.style.transform = 'none';
forceStyleRecalculation();
box.style.transform = null;
// –––––––––––––––––––––––––––––––––––––––––––
after();
forceStyleRecalculation();
}
const forceStyleRecalculation = () => {
return document.body.offsetWidth;
}
forceBoxToPlayTransition(
() => {
box.style.transitionDuration = `0s`;
},
() => {
box.style.transitionDuration = null;
}
);

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade