-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
54 lines (49 loc) · 1.41 KB
/
index.js
File metadata and controls
54 lines (49 loc) · 1.41 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
48
49
50
51
52
53
54
var typer = {
words: ['Software Engineer at Amartha','Front-End Enthusiast', 'Fullstack Web ', 'Software Developer', 'Maker', 'Forward-Thinker' ],
wordIndex: 0,
speed: 150,
nextWordWait: 1000,
html: {
word: document.querySelector('.myWord')
},
init: function init() {
this.typeLetter();
},
typeLetter: function typeLetter() {
var _this = this;
var timer = arguments.length <= 0 || arguments[0] === undefined ? this.speed : arguments[0];
setTimeout(function() {
var word = {
finished: _this.words[_this.wordIndex],
current: _this.readWord()
};
var nextLetterIndex = word.finished.length - word.current.length;
if (nextLetterIndex > 0) {
nextLetterIndex = word.finished.length - nextLetterIndex;
var nextLetter = word.finished[nextLetterIndex];
_this.html.word.innerHTML += nextLetter;
_this.typeLetter();
return;
}
_this.nextWord();
}, timer);
},
readWord: function readWord() {
return this.html.word.innerHTML;
},
clearWord: function clearWord() {
this.html.word.innerHTML = '';
},
nextWord: function nextWord() {
var _this2 = this;
this.wordIndex++;
if (this.wordIndex == this.words.length) {
this.wordIndex = 0;
}
setTimeout(function() {
_this2.clearWord();
_this2.typeLetter(_this2.nextWordWait);
}, this.nextWordWait);
}
};
typer.init();