I'm looking for a way to introduce a delay in my function. Should I enclose the function within a delay function, or is there a different method to ensure that the animation doesn't trigger until 5 seconds after the page has loaded?
var textToType = "blablablabla";
var displayedText = "";
function typeText(fullString, currentlyTyped) {
if (fullString.length != currentlyTyped.length) {
currentlyTyped = fullString.substring(0, currentlyTyped.length + 1);
document.getElementById("logoType").innerText = currentlyTyped;
setTimeout(function() {
typeText(fullString, currentlyTyped)
}, 150);
}
}
document.getElementById("logoType").innerHtml = textToType;
var element = document.createElement('h2');
element.innerHTML = textToType;
textToType = element.textContent;
typeText(textToType, displayedText);
<a class="navbar-brand" id="topper" href="#"><p id="logoType"></p></a>