-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtyping.js
More file actions
47 lines (47 loc) · 1.1 KB
/
Copy pathtyping.js
File metadata and controls
47 lines (47 loc) · 1.1 KB
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
const typing = {
delete: function(speed, selector, bar, callback) {
const text = $(selector).text();
let sliceCount = text.length;
let interval = setInterval(() => {
if (sliceCount != 0) {
let val = text.slice(0, sliceCount);
sliceCount--;
if (!bar) {
$(selector).text(val);
} else if (bar) {
$(selector).text(val + '|');
}
} else if (sliceCount == 0) {
$(selector).text('');
clearInterval(interval);
if (callback) {
callback();
}
}
}, speed);
},
type: function(text, speed, selector, bar, callback) {
const letters = [ ...text ];
let position = 0;
let endstring = '';
let int = setInterval(() => {
let endstr;
if (position != letters.length) {
endstring += letters[position];
position++;
if (!bar) {
endstr = endstring;
} else if (bar) {
endstr = endstring + '|';
}
$(selector).text(endstr);
} else if (position == letters.length) {
$(selector).text(endstring);
clearInterval(int);
if (callback) {
callback();
}
}
}, speed);
}
};