Skip to content

Instantly share code, notes, and snippets.

@vinaydotblog
Created June 30, 2013 18:14
Show Gist options
  • Select an option

  • Save vinaydotblog/5896240 to your computer and use it in GitHub Desktop.

Select an option

Save vinaydotblog/5896240 to your computer and use it in GitHub Desktop.
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment