-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontextMenu.html
More file actions
73 lines (63 loc) · 2.37 KB
/
Copy pathcontextMenu.html
File metadata and controls
73 lines (63 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Full-Screen Context Menu</title>
<style>
/* The custom context menu styles */
#contextMenu {
position: absolute;
background-color: #f0f0f0;
border: 1px solid #ccc;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
visibility: hidden;
z-index: 1000;
width: 200px;
}
/* Style for context menu items */
.menu-item {
padding: 10px;
cursor: pointer;
background-color: #fff;
border-bottom: 1px solid #ccc;
}
.menu-item:hover {
background-color: #e0e0e0;
}
.menu-item:last-child {
border-bottom: none;
}
</style>
</head>
<body oncontextmenu="callMe(event); return false;"> <!-- Prevent the default context menu -->
<h1>To see the full-screen custom context menu, Right-click anywhere</h1>
<!-- The custom context menu -->
<div id="contextMenu" oveflow=>
<div class="menu-item">Option 1</div>
<div class="menu-item">Option 2</div>
<div class="menu-item">Option 3</div>
<div class="menu-item">Option 4</div>
</div>
<script>
function callMe(event) {
// Prevent default browser context menu
event.prevent
// Get the custom context menu element
const contextMenu = document.getElementById("contextMenu");
// Set the position of the custom menu to the mouse's click position
const x = event.pageX;
const y = event.pageY;
// Make sure the menu stays within the viewport
contextMenu.style.left = (x + contextMenu.offsetWidth > window.innerWidth ? x - contextMenu.offsetWidth : x) + "px";
contextMenu.style.top = (y + contextMenu.offsetHeight > window.innerHeight ? y - contextMenu.offsetHeight : y) + "px";
// Show the custom context menu
contextMenu.style.visibility = "visible";
}
// Hide the context menu when clicking anywhere else
document.addEventListener('click', function(event) {
document.getElementById("contextMenu").style.visibility = "hidden";
});
</script>
</body>
</html>