I know I could do it with jQuery, but I want to use only javascript.
I am currently using this code (demo)
<body onload="typeEffect();">
<span id="typeArea"></span>
<script>
var textSpan = document.getElementById("typeArea");
var letterPrint = 0;
function effectOne()
{
textSpan.innerHTML = "H";
}
function effectTwo()
{
textSpan.innerHTML = "He";
}
function effectThree()
{
textSpan.innerHTML = "Hel";
}
function effectFour()
{
textSpan.innerHTML = "Hell";
}
function effectFive()
{
textSpan.innerHTML = "Hello";
}
</script>
</body>
But the result doesn't be like I wanted, it doesn't type each letter but it type a word simultaneously.
I have also tried this javascript code
var letterPrint = 0;
function playEffect()
{
if (letterPrint == 0)
{
textSpan.innerHTML = "H";
var letterPrint = 1;
}
else if (letterPrint == 1)
{
textSpan.innerHTML = "He";
var letterPrint = 2;
}
else if (letterPrint == 2)
{
textSpan.innerHTML = "Hel";
var letterPrint = 3;
}
else if (letterPrint == 3)
{
textSpan.innerHTML = "Hell";
var letterPrint = 4;
}
else if (letterPrint == 4)
{
textSpan.innerHTML = "Hello";
var letterPrint = 5;
}
else
{
textSpan.innerHTML = "Hello";
}
}
setInterval("playEffect()","1000");
But it gives me the same result.
How can I make typewriter effect with javascript? Or it is impossible?