I want to make an animation, like in roulette (or as a spinning drum, or as in a casino), that is, the animation should start quickly and gradually, gradually complete. I tried through cubic-bezier , the result was not satisfactory, the animation turned out to be jerky ... I tried it using pure js, recursion, but I don’t agree with my ideas:
var timer = null; var sec = 1000 / 80; var target = document.getElementById('box'); var dis = target.offsetLeft; document.onclick = function(){ function anim(t){ timer = setInterval(function(){ dis += 1; target.style.left = dis + 'px'; if(target.offsetLeft >= 100) { clearInterval(timer); anim(sec+=10) } }, t); } anim(sec); } #box { background: red; color: #fff; width: 200px; padding: 10px 0; position: absolute; } <div id="box">OK</div> Tell me how to properly implement such an animation?