-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoTupe.js
129 lines (127 loc) · 3.86 KB
/
autoTupe.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
var AutoTyping = (function (e) {
var t = {};
function r(n) {
if (t[n]) return t[n].exports;
var i = (t[n] = { i: n, l: !1, exports: {} });
return e[n].call(i.exports, i, i.exports, r), (i.l = !0), i.exports;
}
return (
(r.m = e),
(r.c = t),
(r.d = function (e, t, n) {
r.o(e, t) || Object.defineProperty(e, t, { enumerable: !0, get: n });
}),
(r.r = function (e) {
"undefined" != typeof Symbol &&
Symbol.toStringTag &&
Object.defineProperty(e, Symbol.toStringTag, { value: "Module" }),
Object.defineProperty(e, "__esModule", { value: !0 });
}),
(r.t = function (e, t) {
if ((1 & t && (e = r(e)), 8 & t)) return e;
if (4 & t && "object" == typeof e && e && e.__esModule) return e;
var n = Object.create(null);
if (
(r.r(n),
Object.defineProperty(n, "default", { enumerable: !0, value: e }),
2 & t && "string" != typeof e)
)
for (var i in e)
r.d(
n,
i,
function (t) {
return e[t];
}.bind(null, i)
);
return n;
}),
(r.n = function (e) {
var t =
e && e.__esModule
? function () {
return e.default;
}
: function () {
return e;
};
return r.d(t, "a", t), t;
}),
(r.o = function (e, t) {
return Object.prototype.hasOwnProperty.call(e, t);
}),
(r.p = ""),
r((r.s = 0))
);
})([
function (e, t, r) {
"use strict";
r.r(t);
t.default = class {
constructor(
e,
t,
{
typeSpeed: r = 150,
deleteSpeed: n = 150,
waitBeforeDelete: i = 1e3,
waitBetweenWords: o = 1e3,
writeWhole: l = !1,
} = {}
) {
(this.selector = e),
(this.text = t),
(this.typeSpeed = r),
(this.deleteSpeed = n),
(this.waitBeforeDelete = i),
(this.waitBetweenWords = o),
(this.writeWhole = l),
(this.el = document.querySelector(e));
}
async start() {
this.el;
for (let e = 0; e < this.text.length; e++) {
const t = this.text[e];
let r = t.split("");
this.writeWhole && (r = [t]),
await this.writeText(r),
e == this.text.length - 1 && (e = -1);
}
}
writeText(e) {
let t = this;
return new Promise((r) => {
const n = this.el;
let i = !1,
o = setInterval(() => {
let l = e.shift();
i && ((i = !1), (l = " " + l)),
(i = " " == l),
(n.innerText += l),
0 == e.length &&
(clearInterval(o),
setTimeout(() => {
let e = setInterval(() => {
const i = n.innerText;
t.writeWhole
? (n.innerText = "")
: (n.innerText = i.substr(0, i.length - 1)),
0 == n.innerText.length &&
(clearInterval(e),
setTimeout(() => r(), this.waitBetweenWords));
}, this.deleteSpeed);
}, this.waitBeforeDelete));
}, this.typeSpeed);
});
}
};
},
]).default;
const exampleText = ['Krish \n Karmacharya','Developer', 'Designer', "Coder"];
const exampleTyping = new AutoTyping('#text', exampleText, {
typeSpeed: 100,
deleteSpeed: 100,
waitBeforeDelete: 2000,
waitBetweenWords: 500,
});
exampleTyping.start()