Advertisement
Guest User

Growing Word

a guest
Sep 3rd, 2020
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const colorMap = ["#5B88BD", "#8FF897", "#A40014"];
  2. let state = 0;
  3.  
  4. function growingWord() {
  5.     const word = document.getElementsByTagName('p')[2];
  6.  
  7.     if (word === 'null') {
  8.         throw new Error("No words for you!");
  9.     };
  10.  
  11.     let fontSize = window.getComputedStyle(word).fontSize.replace("px", "");
  12.  
  13.     if (state >= colorMap.length) {
  14.         state = 0;
  15.     }
  16.  
  17.     word.style.color = colorMap[state];
  18.     state++;
  19.  
  20.     word.style.fontSize = (fontSize === "0" ? "2" : fontSize * 2) + "px";
  21. }    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement