I try to make a rotationg block, which rotation speed is controlled by <input type="range"
. The problem is that I can't find solution that doesn't restart animation when speed updates.
I tried three variants:
Directly set CSS animation speed by JS. — restarts animation;
jQuery's
animate
— doesn't work with transforms;Library
anime.js
— it has method for speed changing but it also restarts animation (or just makes block jump, it's unclear)
What method allows to create smoothly changing by JS animation?
let block = anime({
targets: '#transforms .block',
rotateY: '360',
easing: 'linear',
loop: true,
duration: 1000,
});
var el = document.querySelectorAll('#range')[0];
el.addEventListener('change', function() {
// console.log(value);
// console.log(pos);
var value = this.value;
anime.speed = value/20;
// console.log(block);
})
.block {
width: 500px;
height: 300px;
background-color: red;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.2.0/anime.js"></script>
<div id="transforms">
<div class="block"></div>
</div>
<input id="range" type="range" min="0" max="20" step="1" value="10">
anime.js example code On Codepen