/*
* every jQuery plugin for "typewriter" effect totally sucked
so I hacked something together.
Then I got a lot of interview questions about when a good time
to use javascript closures is, and I kept coming back to this
example; so I generalized it into a proper jQuery plugin.
Feedback appreciated.
*/
!function(e){e.fn.typewriter=function(t){var a={selector:this,extra_char:"",delay:100,trim:!1,callback:null};return t&&e.extend(a,t),function r(c){var t=e(a.selector[c]),n=t.text();a.trim&&(n=e.trim(n)),t.html("").show(),function t(e,l){e.html(n.substr(0,l)+a.extra_char),n.length>=l?setTimeout(function(){t(e,l+1)},a.delay):++c<a.selector.length?r(c):a.callback&&a.callback()}(t,0)}(0),this}}(jQuery); |