使用Anime.js更新数组中的内容

问题描述

我要执行的操作的基本思想是,在用Anime.js设置引号动画的同时,随机循环查找引号数组。

我正在使用时间轴动画,该动画似乎按预期工作。我面临的问题是它没有遇到任何回调选项。在上一次迭代中,我尝试了完成的promise回调,但无济于事。

HTML

 <div class="testimonial">
    <blockquote class="quote">Quote</blockquote>
    <div class="credit">Credit</div>
 </div>

JavaScript

// Sample data
var testimonialPosts = [
    {
        post_content: "Quote text 1"
        post_title: "John Doe"
    },{
        post_content: "Quote text 2"
        post_title: "Sally Smith"
    }
];

var testimonial = document.querySelector('.quote');
var credit = document.querySelector('.credit');
var selectedTestmonial = testimonialPosts[Math.floor(Math.random() * testimonialPosts.length)];

testimonial.innerHTML = selectedTestmonial.post_content;
credit.innerHTML = selectedTestmonial.post_title;

testimonial.innerHTML = testimonial.textContent.replace(/\S/g,"<span class='text'>$&</span>");

const animation = anime.timeline({
    loop: true
})
animation.add({
    targets: '.quote .text',opacity: [0,1],easing: "easeInOutQuad",duration: 250,delay: (el,i) => 25 * (i+1)
})
.add({
    targets: '.credit',duration: 1000,easing: "eaSEOutExpo",i) => 25 * (i+1)
})
.add({
    targets: ['.quote','.credit'],opacity: 0,delay: 4000
});

animation.finished.then(function(){
    selectedTestmonial = testimonialPosts[Math.floor(Math.random() * testimonialPosts.length)];
});

我想念什么?我使用了错误的回调吗?有更好的方法解决这个问题吗?我循环吗?任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)