我试图制作一个旋转块,其旋转速度由
我尝试了三种变体:
<input type="range"
控制。问题在于我找不到不会在速度更新时重新启动动画的解决方案。我尝试了三种变体:
通过JS直接设置CSS动画速度。— 重新启动动画;
jQuery的
animate
— 无法与变换一起使用;库
anime.js
— 它有用于速度更改的方法,但它也会重新启动动画(或只是使块跳跃,不清楚)
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示例代码在Codepen上
Velocity(rotor, { rotateZ: 360, }, {duration: 5000, loop: true, easing: "linear"});
Velocity(rotor, { rotateZ: 360, }, {duration: 1000, loop: true, easing: "linear"});
- partofthething