Javascript tobias ahlin在几个标题上使用的移动信件

Javascript tobias ahlin在几个标题上使用的移动信件,javascript,function,for-loop,while-loop,Javascript,Function,For Loop,While Loop,我正在使用tobias ahlin提供的这个很棒的javascript动画工具,它基于anime.js。我想在几个h2标签上使用这个动画。这是我需要多次使用的代码: // Wrap every letter in a span var textWrapper = document.querySelector('.ml11 .letters'); textWrapper.innerHTML = textWrapper.textContent.replace(/([^\x00-\x80]|\w)/g

我正在使用tobias ahlin提供的这个很棒的javascript动画工具,它基于anime.js。我想在几个h2标签上使用这个动画。这是我需要多次使用的代码:

// Wrap every letter in a span
var textWrapper = document.querySelector('.ml11 .letters');
textWrapper.innerHTML = textWrapper.textContent.replace(/([^\x00-\x80]|\w)/g, "<span class='letter'>$&</span>");

anime.timeline({loop: true})
  .add({
    targets: '.ml11 .line',
    scaleY: [0,1],
    opacity: [0.5,1],
    easing: "easeOutExpo",
    duration: 700
  })
  .add({
    targets: '.ml11 .line',
    translateX: [0, document.querySelector('.ml11 .letters').getBoundingClientRect().width + 10],
    easing: "easeOutExpo",
    duration: 700,
    delay: 100
  }).add({
    targets: '.ml11 .letter',
    opacity: [0,1],
    easing: "easeOutExpo",
    duration: 600,
    offset: '-=775',
    delay: (el, i) => 34 * (i+1)
  }).add({
    targets: '.ml11',
    opacity: 0,
    duration: 1000,
    easing: "easeOutExpo",
    delay: 1000
  });
//将每个字母都用一个空格括起来
var textWrapper=document.querySelector('.ml11.letters');
textWrapper.innerHTML=textWrapper.textContent.replace(/([^\x00-\x80]|\w)/g,“$&”);
动画。时间线({loop:true})
.添加({
目标:'.ml11.line',
scaleY:[0,1],
不透明度:[0.5,1],
放松:“easeOutExpo”,
持续时间:700
})
.添加({
目标:'.ml11.line',
translateX:[0,document.querySelector('.ml11.letters').getBoundingClientRect().width+10],
放松:“easeOutExpo”,
持续时间:700,
延误:100
}).添加({
目标:'.ml11.letter',
不透明度:[0,1],
放松:“easeOutExpo”,
持续时间:600,
偏移量:'-=775',
延迟:(el,i)=>34*(i+1)
}).添加({
目标:'.ml11',
不透明度:0,
持续时间:1000,
放松:“easeOutExpo”,
延误:1000
});

有什么建议吗?非常感谢

您粘贴的代码只是您提供的链接中代码的副本。请发布更多关于你想要达到的目标的细节。在stack over flow中看到一个问题。现在您对该代码的问题是什么?您是否在HTML中使用了两个
?如果是,结果如何?