1

I trying to achieve letter by letter animation with Wow.js and Animate.css.
By default as I understand this can't be done.

I found this great pen on codepen - https://codepen.io/aartiik/pen/jpjaxE
The effect I'm for - 'BounceIn'.
Unfortunately, I can't find the way to make it work with custom text.
Javascript:

new WOW({
  offset: 200
}).init();

var animateCss = [
  "bounce", "flash", "pulse", "rubberBand", "shake", "swing", "tada", "wobble", "jello",
  "bounceIn", "bounceInDown", "bounceInLeft", "bounceInRight", "bounceInUp",
  "fadeIn", "fadeInDown", "fadeInDownBig", "fadeInLeft", "fadeInLeftBig", "fadeInRight", "fadeInRightBig", "fadeInUp", "fadeInUpBig", "flip", "flipInX", "flipInY",
  "lightSpeedIn", "rotateIn", "rotateInDownLeft", "rotateInDownRight", "rotateInUpLeft", "rotateInUpRight",
  "slideInUp", "slideInDown", "slideInLeft", "slideInRight",
  "zoomIn", "zoomInDown", "zoomInLeft", "zoomInRight", "zoomInUp",
  "rollIn"
];

var placeholder = $(".placeholder");
var colorCounter = 0;

for (i = 0; i < animateCss.length; i++) {
  var word = "<div class=\"word\"></div>";
  $(word).appendTo(placeholder);

  for (j = 0; j < animateCss[i].length; j++) {
    var letterDiv = "<div data-wow-delay=\"" + (j * 0.1).toFixed(2) + "s\"  class=\"letter wow " + animateCss[i] + " color" + colorCounter % 7 + "\">" + animateCss[i][j] + "</div>";
    $(letterDiv).appendTo($(".word").last());
    colorCounter++;
  }
}
Arthur G
  • 25
  • 1
  • 9

1 Answers1

0

That example is looping through each animation string and performing letter-by-letter animation for the name of the animation string itself. If you remove that outer for-loop you can use the inner for-loop to do the same thing with whatever text you like.

Here's a fork where I put a data-text attribute on a div, and loop through each letter of the attribute's value:

https://codepen.io/p8ntballer052/pen/ajgQZm

<div class="word bounce" data-text="Bouncing Text">

var target = $(".bounce"),
    targetText = target[0].dataset.text;

for (j = 0; j < targetText.length; j++) {
    var letterDiv = "<div data-wow-delay=\"" + (j * 0.1).toFixed(2) + "s\"  class=\"letter wow bounceIn\">" + targetText[j] + "</div>";
    $(letterDiv).appendTo(target.last());
}
CDelaney
  • 1,238
  • 4
  • 19
  • 36