Created
December 21, 2012 09:30
-
-
Save furugomu/4351730 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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