当前位置:K88软件开发文章中心编程语言JavaScriptJS01 → 文章内容

打字效果的JS库TheaterJS

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-4 8:49:53

-->

在之前的文章里也介绍了一个打字效果的jQuery插件-typer.js。今天再给大家分享一个模拟人类打字的js插件TheaterJS,TheaterJS功能更加丰富,包含多个角色管理、事件处理等。

1、引入TheaterJS.js

1
<script src=“path/to/theater.js”></script>

2、TheaterJS.js的使用

1
2
<div id=“raykaeso”></div>
<div id=“leixuesong”></div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<script src=“path/to/theater.js”></script>
<script>
//TheaterJS初始化
var theater = new TheaterJS();

//描述角色
theater
.describe(“raykaeso”, .8, “#raykaeso”)
.describe(“leixuesong”, .6, “#leixuesong”);

// 写剧本
theater
.write(“raykaeso:leixuesong.”, 600)
.write(“leixuesong:What?”, 400)
.write(“raykaeso:I am…”, 400, ” your?friend.”);

// 监听事件
theater
.on(“say:start, erase:start”, function () {
// add blinking caret
})
.on(“say:end, erase:end”, function () {
// remove blinking caret
})
.on(“*”, function () {
// do something
});
</script>

TheaterJS.js github地址https://github.com/Zhouzi/TheaterJS


打字效果的JS库TheaterJS