1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
$.fn.typewriter = function(opt,callback) {
var i=0;
var typeone = function(self, text, content) {
if (text.length > 0) {
i=i+1;
var next = text.match(/(\s*(<[^>]*>)?)*(&.*?;|.?)/)[0];
text = text.substr(next.length);
$(self).html(content+next);
setTimeout(function(){
typeone(self, text, content+next);
}, opt['delay']);
if(text.length==0) if (callback!=null) callback();
}
}
this.each(function() {
opt = opt || { 'delay': 1 };
typeone(this, $(this).html(), '');
});
return this;
} |
Partager