|
@@ -319,17 +319,10 @@
|
|
|
|
|
|
|
|
// 自定义右键菜单功能
|
|
// 自定义右键菜单功能
|
|
|
function initOptionMenu(doc) {
|
|
function initOptionMenu(doc) {
|
|
|
- // 移动到中心
|
|
|
|
|
- function center(contextMenu) {
|
|
|
|
|
- // 隐藏菜单后,将菜单移动到屏幕中心
|
|
|
|
|
- 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";
|
|
|
|
|
|
|
+ // 隐藏菜单后,将菜单移动到屏幕内
|
|
|
|
|
+ function inScreen(contextMenu) {
|
|
|
|
|
+ contextMenu.style.left = "2px";
|
|
|
|
|
+ contextMenu.style.top = "2px";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 初始化样式
|
|
// 初始化样式
|
|
@@ -450,7 +443,7 @@
|
|
|
doc.execCommand("selectAll");
|
|
doc.execCommand("selectAll");
|
|
|
}
|
|
}
|
|
|
contextMenu.classList.remove("show");
|
|
contextMenu.classList.remove("show");
|
|
|
- center(contextMenu);
|
|
|
|
|
|
|
+ inScreen(contextMenu);
|
|
|
};
|
|
};
|
|
|
contextMenu.appendChild(li);
|
|
contextMenu.appendChild(li);
|
|
|
});
|
|
});
|
|
@@ -505,7 +498,7 @@
|
|
|
}
|
|
}
|
|
|
// 隐藏菜单
|
|
// 隐藏菜单
|
|
|
contextMenu.classList.remove("show");
|
|
contextMenu.classList.remove("show");
|
|
|
- center(contextMenu);
|
|
|
|
|
|
|
+ inScreen(contextMenu);
|
|
|
};
|
|
};
|
|
|
contextMenu.appendChild(li);
|
|
contextMenu.appendChild(li);
|
|
|
});
|
|
});
|
|
@@ -540,14 +533,14 @@
|
|
|
} else {
|
|
} else {
|
|
|
// 如果没有定义菜单选项,则隐藏菜单
|
|
// 如果没有定义菜单选项,则隐藏菜单
|
|
|
contextMenu.classList.remove("show");
|
|
contextMenu.classList.remove("show");
|
|
|
- center(contextMenu);
|
|
|
|
|
|
|
+ inScreen(contextMenu);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 点击其他地方隐藏菜单
|
|
// 点击其他地方隐藏菜单
|
|
|
doc.addEventListener("click", function () {
|
|
doc.addEventListener("click", function () {
|
|
|
contextMenu.classList.remove("show");
|
|
contextMenu.classList.remove("show");
|
|
|
- center(contextMenu);
|
|
|
|
|
|
|
+ inScreen(contextMenu);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// 阻止菜单内部的点击事件冒泡
|
|
// 阻止菜单内部的点击事件冒泡
|