Skip to content

Instantly share code, notes, and snippets.

@kindlyfire
Created January 10, 2016 16:22
Show Gist options
  • Save kindlyfire/4b35966cb5a7966342ef to your computer and use it in GitHub Desktop.
Save kindlyfire/4b35966cb5a7966342ef to your computer and use it in GitHub Desktop.
function Typed()
{
self = this;
self.delay = 50;
self.pos = 1;
self.text = "";
function init(elem, delay) {
self.delay = delay;
self.text = $(elem).html();
}
this.type = function(elem, delay)
{
if(self.text == "") init(elem, delay);
if(self.pos > self.text.length) return true;
$(elem).html(self.text.substr(0, self.pos));
self.pos++;
window.setTimeout(function() {
self.type(elem, self.delay);
}, self.delay);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment