vinnizworld
6/30/2013 - 6:14 PM

Script to give typing effect to the given string.

Script to give typing effect to the given string.

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        body { background: #f6f6f6; }
        textarea { width: 100%; border: 1px inset #ddd; padding: 5px; font-family: sans-serif; background: #f9f9f9; }
        textarea:focus { outline: 2px solid #25547b; border-radius: 5px; }
    </style>
</head>
<body>

    <textarea name="" style="width: 100%;" id="" cols="30" rows="10"></textarea>
    <script>
        var tmp = '', text = 'My Name is Vinay Aggarwal.', count =0, ta = document.querySelector('textarea');
        var timer = setInterval(function(){
            if( !text[count] ){ clearInterval(timer); }
            ta.value = tmp;
            tmp += text[count++];
        }, 100);
    </script>
</body>
</html>