首页 > 其他 > 详细

打字效果

时间:2014-10-18 03:10:55      阅读:262      评论:0      收藏:0      [点我收藏+]
(function($) {
	$.fn.typewriter = function(cb) {
		this.each(function() {
			var $ele = $(this), str = $ele.html(), progress = 0;
			$ele.html(‘‘);
			var timer = setInterval(function() {
				var current = str.substr(progress, 1);
				if (current == ‘<‘) {
					progress = str.indexOf(‘>‘, progress) + 1;
				} else {
					progress++;
				}
			$ele.html(str.substring(0, progress) + (progress & 1 ? ‘_‘ : ‘‘));
				if (progress >= str.length) {
					clearInterval(timer);
					if(typeof cb == ‘function‘){
						cb();
					}
					if(str[str.length-1] == ‘_‘){
						str=substr(0,str.length-1);
					} 
					$ele.html(str);		
				}
			}, 75);
		});
		return this;
	};
})(jQuery);


打字效果

原文:http://my.oschina.net/wizardpisces/blog/333970

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!