Skip to content

Instantly share code, notes, and snippets.

@furugomu
Created December 21, 2012 09:30
Show Gist options
  • Save furugomu/4351730 to your computer and use it in GitHub Desktop.
Save furugomu/4351730 to your computer and use it in GitHub Desktop.
jQuery.fn.typewriter = function(text, options) {
if (typeof(options) === 'undefined') options = {};
if (typeof(options.wait) === 'undefined') options.wait = 50;
if (options.wait <= 0) return this.text(text);
var type = function(element, wait, text, i) {
if (i >= text.length) return;
element.insertAdjacentText('beforeend', text.charAt(i));
setTimeout(function(){type(element, wait, text, i+1)}, wait);
}
this.empty().each(function(i) {
type(this, options.wait, text, 0);
});
return this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment