Skip to content

Instantly share code, notes, and snippets.

@shapkarin
Last active August 29, 2015 14:06
Show Gist options
  • Save shapkarin/0fb50100de3a8c8f3e64 to your computer and use it in GitHub Desktop.
Save shapkarin/0fb50100de3a8c8f3e64 to your computer and use it in GitHub Desktop.
Typewriter Effect Implementations (with JQuery)
//this solution is much better
function typewriter(text, name){
var input = form.find('input[name="'+ name + '"]').val('')[0],
s = text.split('').reverse(),
len = s.length-1,
var initInterval = setInterval(function(){
if( s.length ){
var c = s.pop();
input.value += c;
}
else clearInterval(initInterval);
},150);
}
//hmm has bugs if change tab while writing into div
function typewriter(text, name) {
var input = form.find('input[name="'+ name + '"]');
$.each(text.split(''), function(i, letter){
setTimeout(function(){
input.val(input.val() + letter);
}, 70*i);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment