-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-menu.html
More file actions
100 lines (92 loc) · 2.37 KB
/
test-menu.html
File metadata and controls
100 lines (92 loc) · 2.37 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test Context Menu</title>
<style>
.context-menu {
position: fixed;
background: #ece9d8;
border: 2px outset #fff;
box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.4);
display: flex;
flex-direction: column;
z-index: 10003;
min-width: 200px;
padding: 2px;
}
.context-menu-item {
padding: 4px 24px 4px 28px;
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
background: transparent;
border: none;
text-align: left;
position: relative;
}
.context-menu-item:hover {
background: #0831d9;
color: white;
}
.context-submenu {
position: absolute;
left: calc(100% - 2px);
top: -2px;
background: #ece9d8;
border: 2px outset #fff;
box-shadow: 3px 3px 5px rgba(0, 0, 0, 0.4);
display: none !important;
flex-direction: column;
min-width: 180px;
padding: 2px;
z-index: 10004;
}
.context-menu-item:hover > .context-submenu {
display: flex !important;
}
.context-menu-item.has-submenu::after {
content: '▶';
position: absolute;
right: 8px;
font-size: 8px;
}
</style>
</head>
<body style="padding: 50px;">
<h1>Test Context Menu</h1>
<p>Right-click anywhere to see the menu</p>
<div class="context-menu" id="context-menu" style="display: none;">
<button class="context-menu-item has-submenu">
<div>Share with a friend...</div>
<div class="context-submenu">
<button class="context-menu-item">
<div>Share on Twitter</div>
</button>
<button class="context-menu-item">
<div>Share on LinkedIn</div>
</button>
</div>
</button>
<button class="context-menu-item">
<div>Copy Logo</div>
</button>
<button class="context-menu-item">
<div>Refresh</div>
</button>
</div>
<script>
document.addEventListener('contextmenu', (e) => {
e.preventDefault();
const menu = document.getElementById('context-menu');
menu.style.left = e.clientX + 'px';
menu.style.top = e.clientY + 'px';
menu.style.display = 'flex';
});
document.addEventListener('click', () => {
document.getElementById('context-menu').style.display = 'none';
});
</script>
</body>
</html>