how to make this js animation effect for multi line & animate one by one?

て烟熏妆下的殇ゞ 提交于 2020-06-09 05:38:05

问题


how to make this js animation effect for multi line & animate one by one ?

Just like

<h1 class="rks1">  First Line </h1>
<h1 class="rks1">  Then Second Line </h1>
<h1 class="rks1">  Then Third Line </h1>
<h1 class="rks1">  Then Fourth Line </h1>
<h1 class="rks1">  Then Fifth Line </h1>

& more... then restart first line or i think it may like:

<h1 class="rks1">  First Line </h1>
<h1 class="rks2">  Then Second Line </h1>
<h1 class="rks3">  Then Third Line </h1>
<h1 class="rks4">  Then Fourth Line </h1>
<h1 class="rks5">  Then Fifth Line </h1>

& more... then restart first line

var textWrapper = document.querySelector('.rks1');

textWrapper.innerHTML = textWrapper.textContent.replace(/(\S*)/g, m => {
  return `<span class="word">` +
    m.replace(/(-|)?\S(-|@)?/g, "<span class='letter'>$&</span>") +
    `</span>`;
});

var targets = Array.from(document.querySelectorAll('.rks1 .letter'));

anime.timeline({
  loop: true,
})
  .add({
    targets: targets,
    scale: [3,1],
    scaleY: [1.5,1],
    opacity: [0,1],
    translateZ: 0,
    easing: "easeOutExpo",
    duration: 400,
    delay: (el, i) => 60*i
  }).add({
    targets: targets.reverse(),
    scale: [1,3],
    scaleY: [1,1.5],
    opacity: [1,0],
    translateZ: 0,
    easing: "easeOutExpo",
    duration: 100,
    delay: (el, i) => 30*i
  }).add({
    opacity: 0,
    duration: 2000,
    easing: "easeOutExpo",
    delay: 800
  });
.rks1 {
font-weight: 900;
font-size: 2.5em;
font-family: rr;
}

.rks1 .letter {
display: inline-block;
line-height: 1em;
}

.word {
white-space: nowrap;
}

.span {
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
   
<h1 class="rks1"> First animate this line Okay </h1>
<h1 class="rks1">  Then Second Line </h1>
<h1 class="rks1">  Then Third Line </h1>
<h1 class="rks1">  Then Fourth Line </h1>
<h1 class="rks1">  Then Fifth Line </h1>


or may be this format :



& more...
i want to make this like firstly animate one line and then on same place animate next line, then next, same as as so on. hay ! stackoverflow community anybody make change this javascript in this feature, make it fast plz. this is very important to me.

回答1:


Wraps all letters and words with span using querySelectorAll and forEach

var textWrappers = document.querySelectorAll('.rks1');

textWrappers.forEach(textWrapper => {
  textWrapper.innerHTML = textWrapper.textContent.replace(/(\S*)/g, m => {
    return `<span class="word">` +
      m.replace(/(-|)?\S(-|@)?/g, "<span class='letter'>$&</span>") +
      `</span>`;
  });
});

var targets = Array.from(document.querySelectorAll('.rks1 .letter'));

anime.timeline({
    loop: true,
  })
  .add({
    targets: targets,
    scale: [3, 1],
    scaleY: [1.5, 1],
    opacity: [0, 1],
    translateZ: 0,
    easing: "easeOutExpo",
    duration: 400,
    delay: (el, i) => 60 * i
  }).add({
    targets: targets.reverse(),
    scale: [1,3],
    scaleY: [1,1.5],
    opacity: [1,0],
    translateZ: 0,
    easing: "easeOutExpo",
    duration: 100,
    delay: (el, i) => 30*i
  }).add({
    opacity: 0,
    duration: 2000,
    easing: "easeOutExpo",
    delay: 800
  })
.rks1 {
  font-weight: 900;
  font-size: 2.5em;
  font-family: rr;
}

.rks1 .letter {
  display: inline-block;
  line-height: 1em;
}

.word {
  white-space: nowrap;
}

.span {}
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.0.2/anime.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<h1 class="rks1"> First animate this line Okay </h1>
<h1 class="rks1"> Then Second Line </h1>
<h1 class="rks1"> Then Third Line </h1>
<h1 class="rks1"> Then Fourth Line </h1>
<h1 class="rks1"> Then Fifth Line </h1>


or may be this format : & more...


来源:https://stackoverflow.com/questions/62245714/how-to-make-this-js-animation-effect-for-multi-line-animate-one-by-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!