---
title: "实现打字机打字的效果"
author: "小杨学JAVA"
date: "2014-01-15T10:10:14Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2014-01-15T10:10:14Z"
id: 2004145
url: "https://z3sm2012.iteye.com/blog/2004145"
---

```
(function(a) {
	a.fn.typewriter = function() {
		this.each(function() {
			var d = a(this),
			c = d.html(),
			b = 0;
			d.html("");
			var e = setInterval(function() {
				var f = c.substr(b, 1);
				if (f == "<") {
					b = c.indexOf(">", b) + 1
				} else {
					b++
				}
				d.html(c.substring(0, b) + (b & 1 ? "_": ""));
				if (b >= c.length) {
					clearInterval(e)
				}
			},
			75)
		});
		return this
	}
})(jQuery);
```

 转，不是原创用来学习