wobble.js 715 B

12345678910111213141516171819
  1. // This code came from https://codepen.io/queenadreena/pen/oKGyYq
  2. // Create array of any elements with "wobble" class
  3. const all = document.querySelectorAll('.wobble');
  4. // Iterate through each "wobble"
  5. all.forEach(el => {
  6. // Get the text content of the element
  7. let text = el.textContent;
  8. // Create an array of separate letters
  9. text = text.split("");
  10. // Iterate through each letter and give it its own span element and individual animation delay offset
  11. const textCode = text.map((x, idx) => {
  12. let delay = (idx + 1) * 50;
  13. return `<span style="animation-delay: ${delay}ms">${x}</span>`;
  14. })
  15. // replace the element's html with our dynamically created html
  16. el.innerHTML = textCode.join("");
  17. });