问题描述
尝试一个简单的循环动画,在 animejs 循环中为每次迭代更改其参数。此代码更改了变量值,但未应用它们。值通过迭代保持不变。我怎样才能做到这一点?
let
R = Math.floor((Math.random() * 255)),G = Math.floor((Math.random() * 255)),B = Math.floor((Math.random() * 255)),dur = Math.floor((Math.random() * 4000));
anime({ // <------------------------------------- Anime JS function
targets: '.element',color: `rgb(${R},${G},${B})`,// <----------- Values I would like to change on each iteration
duration: dur,// <--------------------------- Values I would like to change on each iteration
loop: true,easing: 'linear',loopComplete: function (anim) { // <----------- Loop iteration callback
R = Math.floor((Math.random() * 255));
G = Math.floor((Math.random() * 255));
B = Math.floor((Math.random() * 255));
dur = Math.floor((Math.random() * 2000));
console.log(R + ',' + G + ',' + B); // <---- Checked. RGB values are changing on each iteration.
},});
let
R = Math.floor((Math.random() * 255)),dur = Math.floor((Math.random() * 4000));
anime({
targets: '#square',duration: dur,loop: true,loopBegin: function (anim) {
R = Math.floor((Math.random() * 255));
G = Math.floor((Math.random() * 255));
B = Math.floor((Math.random() * 255));
dur = Math.floor((Math.random() * 2000));
console.log(R + ',' + B);
},});
#square {
font-size: 100px
}
<script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<div id="square">square</div>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)