Ver Fonte

【修复】隐藏右键菜单后将其移动到屏幕中心

- 在点击事件处理中添加代码,隐藏菜单后计算屏幕中心位置
- 将菜单移动到屏幕中心,以提高用户体验
PJ568 há 1 ano atrás
pai
commit
f8fbc6e9cb
1 ficheiros alterados com 9 adições e 0 exclusões
  1. 9 0
      index.html

+ 9 - 0
index.html

@@ -534,6 +534,15 @@
         // 点击其他地方隐藏菜单
         doc.addEventListener("click", function () {
           contextMenu.classList.remove("show");
+          // 隐藏菜单后,将菜单移动到屏幕中心
+          const windowWidth = window.innerWidth;
+          const windowHeight = window.innerHeight;
+          const menuWidth = contextMenu.offsetWidth;
+          const menuHeight = contextMenu.offsetHeight;
+          const centerX = (windowWidth - menuWidth) / 2;
+          const centerY = (windowHeight - menuHeight) / 2;
+          contextMenu.style.left = centerX + "px";
+          contextMenu.style.top = centerY + "px";
         });
 
         // 阻止菜单内部的点击事件冒泡