|
@@ -8,20 +8,28 @@ export class Tip {
|
|
|
|
|
|
public show(text: string, time: number = 6000) {
|
|
|
this.element.className = "vditor-tip vditor-tip--show";
|
|
|
-
|
|
|
if (time === 0) {
|
|
|
this.element.innerHTML = `<div class="vditor-tip__content">${text}
|
|
|
<div class="vditor-tip__close">X</div></div>`;
|
|
|
this.element.querySelector(".vditor-tip__close").addEventListener("click", () => {
|
|
|
this.hide();
|
|
|
});
|
|
|
- return;
|
|
|
+ } else {
|
|
|
+ this.element.innerHTML = `<div class="vditor-tip__content">${text}</div>`;
|
|
|
+ setTimeout(() => {
|
|
|
+ this.hide();
|
|
|
+ }, time);
|
|
|
}
|
|
|
|
|
|
- this.element.innerHTML = `<div class="vditor-tip__content">${text}</div>`;
|
|
|
+ // 需在动画结束后才能确定位置
|
|
|
+ this.element.removeAttribute("style")
|
|
|
setTimeout(() => {
|
|
|
- this.hide();
|
|
|
- }, time);
|
|
|
+ const rect = this.element.getBoundingClientRect();
|
|
|
+ if (rect.top < 46) {
|
|
|
+ this.element.style.position = "fixed"
|
|
|
+ this.element.style.top = "46px"
|
|
|
+ }
|
|
|
+ }, 150);
|
|
|
}
|
|
|
|
|
|
public hide() {
|