Jelajahi Sumber

:bug: fix https://github.com/Vanessa219/vditor/issues/1223

Vanessa 3 tahun lalu
induk
melakukan
bcf775bb70
2 mengubah file dengan 15 tambahan dan 7 penghapusan
  1. 2 2
      .prettierrc
  2. 13 5
      src/ts/tip/index.ts

+ 2 - 2
.prettierrc

@@ -12,8 +12,8 @@
 	"requirePragma": false,
 	"semi": false,
 	"singleQuote": false,
-	"tabWidth": 2,
+	"tabWidth": 4,
 	"trailingComma": "es5",
 	"useTabs": false,
 	"vueIndentScriptAndStyle": false
-}
+}

+ 13 - 5
src/ts/tip/index.ts

@@ -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() {