forked from ygs-code/vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contextmenu.html
54 lines (49 loc) · 1.24 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
ul, li {
margin: 0;
padding: 0;
}
#myMenu{
list-style: none;
width: 150px;
border: 1px solid #ccc;
border-bottom: none;
position: absolute;
display: none;
}
#myMenu li{
border-bottom: 1px solid #ccc;
padding: 5px 10px;
cursor: pointer;
}
#myMenu li:hover{
background-color: #ccc;
}
</style>
</head>
<body>
<ul id="myMenu">
<li>右键想干什么?</li>
<li>想看源代码?</li>
<li>还是想审查元素?</li>
</ul>
<script>
var myMenu = document.getElementById("myMenu");
document.addEventListener("contextmenu", function(event){
event.preventDefault();
myMenu.style.display = "block";
//获取鼠标视口位置
myMenu.style.top = event.clientY + "px";
myMenu.style.left = event.clientX + "px";
});
document.addEventListener("click", function(event){
myMenu.style.display = "none";
});
</script>
</body>
</html>