Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript typewriter effect

// this function performs a typewriter effect on an element from the HTML DOM
function TypeWriter(target, text, delay, clearText = false) {
	if (target.textContent === text) {
		return;
	}
	if (clearText) {
		target.textContent = "";
	}
	let _delay = 0;
	for (let i = 0; i < text.length; i++) {
		_delay += delay;
		window.setTimeout(function() {
			target.textContent += text[i];
		}, _delay);
	}
}
 
PREVIOUS NEXT
Tagged: #javascript #typewriter #effect
ADD COMMENT
Topic
Name
7+8 =