JSFiddle - React, Tailwind, and code Playground

by Ravichandra Thota

HTML

<div id="container">

<div class="typing">
  <h1>This is a Heading skjhfksjhfsdkjfhdsfkjshdfkj sdskdjf sdfsdf</h1>
</div>
    
</div>

CSS

h1 {
    color:blue;
} 

h2 {
    color: red;
}

p {
    color:green;
}

JavaScript

var $el = $('.typing'),  
    txt = $el.text(),
    txtLen = html.length,
    timeOut,
    char = 0;

$el.text('|');

(function typeIt() {   
    var humanize = Math.round(Math.random() * (200 - 30)) + 30;
    timeOut = setTimeout(function() {
        char++;
        var type = txt.substring(0, char);
        $el.html(type + '|');
        typeIt();

        if (char == txtLen) {
            $el.html($el.html().slice(0, -1)); // remove the '|'
            clearTimeout(timeOut);
        }

    }, humanize);
}());