要制作一个contextmenu快捷菜单,可以按照以下步骤进行操作:
<button id="contextMenuBtn">右键点击我</button>
<menu id="contextMenu">
<menuitem label="菜单项1"></menuitem>
<menuitem label="菜单项2"></menuitem>
</menu>
#contextMenu {
display: none;
position: absolute;
background-color: #f1f1f1;
border: 1px solid #ccc;
padding: 5px;
}
var contextMenu = document.getElementById("contextMenu");
var contextMenuBtn = document.getElementById("contextMenuBtn");
contextMenuBtn.addEventListener("contextmenu", function(event) {
event.preventDefault();
contextMenu.style.display = "block";
contextMenu.style.left = event.clientX + "px";
contextMenu.style.top = event.clientY + "px";
});
document.addEventListener("click", function() {
contextMenu.style.display = "none";
});
通过以上步骤,就可以制作一个简单的contextmenu快捷菜单。您也可以根据实际需求对菜单进行更进一步的样式和功能定制。