打字效果

var wordCtrl = function(){
	var cbfun=null;
	var obj = {
		now:0,
		maxLen:0,
		speed:80,
		wArr:[],
		show:function(){
			if(this.now>=this.maxLen) {
				if(typeof(cbfun)=='function') {
					cbfun();
				}
				return;
			}
			this.wArr[this.now].css({'visibility':'visible'});
			this.now++;
			if(this.uto) {
				clearTimeout(this.uto);
			}
			this.uto = setTimeout(function(){
				obj.show();
			},this.speed);
		},
		init:function(txtObj,cf){
			cbfun=cf;
			this.now=0;
			this.wArr = [];
			var txt = $(txtObj).html();
			var arr = txt.split('');
			var len  = arr.length;
			if(len==0) {
				return;
			}
			var tmp,tarr,tlen,mlen;
			mlen=0;
			for(var i=0;i<len;i++) {
				tmp = arr[i];
				tarr = tmp.split('');
				tlen = tarr.length;
				for(var j=0;j<tlen;j++) {
					tarr[j] = '<span class="word">'+tarr[j]+'</span>';
					mlen++;
				}
				arr[i] = tarr.join('');
			}
			this.maxLen = mlen;
			$(txtObj).html(arr.join('<br/>'));
			$(txtObj).find('.word').each(function(){
				obj.wArr.push($(this));
			});
		}
	}
	return obj;
}
.word{visibility:hidden;}