如何解决更改每次循环迭代的参数
尝试一个简单的循环动画,在 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 举报,一经查实,本站将立刻删除。