I am using this typewriter effect made with JavaScript, HTML and CSS (method seen below) but I am wanting to take it a step further. Is there a way I can change the font of each word that is typed? I've looked around for solutions but I honestly don't even know what to search for. Please let me know if this is possible.
var words = ['Design','Create','Dream', 'Inspire'], currentStep = 0, textEl = document.querySelector('.change-text'), oldWord = ''; setTimeout(changeWord, 2000); function changeWord() { oldWord = textEl.innerHTML; // check if there is a word atm or not if (oldWord.length < 1) { if (currentStep !== words.length -1) { currentStep ++; }else { currentStep = 0; } addNextWord(); } else { setTimeout(deleteWord, 1400); } }; function deleteWord() { var WordLength = oldWord.length, currentWord = textEl.innerHTML, currentLength = currentWord.length; // The word is deleted so, start adding in the new one if (currentLength < 1) { changeWord(); return; } // Remove a charachter textEl.innerHTML = currentWord.substring(0, currentLength - 1); setTimeout(deleteWord, 140); } function addNextWord() { var currentWord = textEl.innerHTML, currentLength = currentWord.length, nextWord = words[currentStep], nextWordLength = nextWord.length; if (currentLength === nextWordLength) { changeWord(); return; } // add a charachter textEl.innerHTML = nextWord.substring(0, currentLength + 1); setTimeout(addNextWord, 240); } #first-section{ z-index: 4; background-image: linear-gradient(to top, #205ba8 0%, #537895 100%); position: relative; width: 100%; min-height: 100vh; display: flex; } .inspire{ padding: 0; margin: 0; position: absolute; top: 0; left: 10%; color: #fff; font-size: 50px; font-weight: 600; font-family: sans-serif; } .change-text { position: absolute; bottom: 0; left: 10%; color: #fff; line-height: 500px; font-size: 70px; font-weight: 900; cursor: context-menu; } @keyframes blinking { 0% { opacity: 0; } 50% { opacity: 0; } 51% { opacity: 1; } 100% { opacity: 1; } } .change-text:after { content: '_'; animation: blinking 1.2s infinite; } <section id="first-section"> <h1 class="inspire" data-aos="fade-right"> HERE TO: </h1> <div class="change-text" data-aos="fade-right">Design</div> </section>
<span>) having a class defining the font (or an inline style attribute).here to:; nothing is happening,. In answers also...