<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
html
<div id="customMenuElement">Right click me!</div>
<ul id="customMenu">
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
</ul>
<body>
js
<script>
const customMenuElement = document.querySelector("#customMenuElement");
const customMenu = document.querySelector("#customMenu");
customMenuElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
customMenu.style.top = `${event.clientY}px`;
customMenu.style.left = `${event.clientX}px`;
customMenu.classList.add("show");
});
</script>
</body>
<style>
css
#customMenu {
display: none;
position: absolute;
list-style: none;
padding: 0;
margin: 0;
background-color: white;
border: 1px solid black;
}
#customMenu.show {
display: block;
}
#customMenu li {
padding: 5px 10px;
}
#customMenu li:hover {
background-color: lightblue;
}
</style>
</html>