// Typewriter effect const typedTextSpan = document.querySelector(".typed-text"); const cursorSpan = document.querySelector(".cursor"); const textArray = ["Safety of Mississippi Roads"]; const typingDelay = 150; const erasingDelay = 100; const newTextDelay = 500; let textArrayIndex = 0; let charIndex = 0; function type() { if (charIndex < textArray[textArrayIndex].length) { if (!cursorSpan.classList.contains("typing")) cursorSpan.classList.add("typing"); typedTextSpan.textContent += textArray[textArrayIndex].charAt(charIndex); charIndex++; setTimeout(type, typingDelay); } else { cursorSpan.classList.remove("typing"); setTimeout(erase, newTextDelay); } } document.addEventListener("DOMContentLoaded", function () { if (textArray.length) setTimeout(type, newTextDelay + 250); });