-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontextmenu.html
68 lines (56 loc) · 1.72 KB
/
contextmenu.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html lang="en">
<head>
<style>
html, body{
width: 100%;
height: 100%;
font-family: "Open Sans", sans-serif;
padding: 0;
margin: 0;
}
#context-menu{
position: fixed;
z-index: 10000;
width: 150px;
background: #1b1a1a;
border-radius: 5px;
display: none;
}
#context-menu.visible{
display: block;
}
#context-menu .item{
padding: 8px 10px;
font-size: 15px;
color: #eee;
cursor: pointer;
border-radius: inherit;
}
#context-menu .item:hover{
background: #343434;
}
</style>
</head>
<body>
<div id="context-menu">
<div class="item">Change Link</div>
</div>
<script>
const contextMenu = document.getElementById("context-menu");
const scope = document.querySelector("body");
scope.addEventListener("contextmenu", (event) => {
event.preventDefault();
const { clientX: mouseX, clientY: mouseY } = event;
contextMenu.style.top = `${mouseY}px`;
contextMenu.style.left = `${mouseX}px`;
contextMenu.classList.add("visible");
});
scope.addEventListener("click", (e) => {
if (e.target.offsetParent != contextMenu) {
contextMenu.classList.remove("visible");
}
});
</script>
</body>
</html>