-
Notifications
You must be signed in to change notification settings - Fork 0
/
page-toast.js
44 lines (40 loc) · 1.03 KB
/
page-toast.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
class PageToast extends HTMLElement{
constructor() {
super();
this.initialized = false;
this.timer = 0;
}
connectedCallback() {
if (this.initialized) {
return;
}
this.initialized = true;
this.style.position = 'fixed';
this.style.zIndex = '9999999';
this.style.bottom = '20px';
this.style.width = 'max-content';
this.style.padding = '10px 20px';
this.style.left = '0px';
this.style.right = '0px';
this.style.margin = 'auto';
this.style.borderRadius = '40px'
this.style.background = 'rgba(0,0,0,.8)';
this.style.color = '#fff';
this.style.pointerEvents = 'none';
this.style.opacity = '0';
this.style.transition = 'opacity 150ms ease-out';
this.textContent = 'toast';
}
show(msg) {
if (this.timer) {
window.clearTimeout(this.timer);
}
this.style.opacity = '1';
this.textContent = msg;
this.timer = window.setTimeout(this.hide.bind(this), 2000);
}
hide() {
this.style.opacity = '0';
}
}
customElements.define('page-toast', PageToast);