-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextMessage.js
52 lines (40 loc) · 1.22 KB
/
TextMessage.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
class TextMessage {
constructor({text, onComplete}) {
this.text = text;
this.onComplete = onComplete;
this.element = null;
}
createElement() {
this.element = document.createElement("div");
this.element.classList.add("TextMessage");
this.element.innerHTML=(`
<p class="TextMessage_p"></p>
<button class="TextMessage_button">Next</button>
`)
// Эфект пишуший машинки
this.revealingText = new ReavalingText({
element: this.element.querySelector(".TextMessage_p"),
text: this.text,
})
this.element.querySelector("button").addEventListener("click", () =>{
this.done();
})
this.actionListener = new KeyPressListener("Enter", () => {
this.done();
})
}
done(){
if(this.revealingText.isDone){
this.element.remove();
this.onComplete();
this.actionListener.unbind()
}else{
this.revealingText.warpToDone();
}
}
init(container) {
this.createElement();
container.appendChild(this.element);
this.revealingText.init();
}
}