当前位置:网站首页>自定义浏览器默认右击菜单栏
自定义浏览器默认右击菜单栏
2022-07-26 12:08:00 【爱学习的佳】
本文简单介绍了 如何更换浏览器的默认右击菜单栏
在页面的任意位置点击右键,自定义的菜单都会跟随鼠标的点击位置来显示出来
效果图:

话不多说,直接上代码!
<!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>加强自定义菜单</title>
<style>
* {
padding: 0;
margin: 0;
}
ul {
width: 230px;
background-color: rgb(255, 255, 255);
position: fixed;
left: 100px;
top: 100px;
border: 1px solid rgb(105, 105, 105);
padding-top: 10px;
text-indent: 10px;
list-style: none;
display: none;
}
li{
margin-bottom: 13px;
color: #000;
font: 800 16px/26px "宋体";
border-bottom: 1px solid #ccc;
}
li:last-child{
border-bottom: none;
margin-bottom: 0;
padding-bottom: 5px;
}
li:hover{
background-color: rgb(69, 255, 193);
box-shadow: 0px 0px 26px 0px rgb(69, 255, 193);
}
ul li:first-child:hover{
background-color: rgb(91, 230, 255);
box-shadow: 0px 0px 26px 0px rgb(91, 230, 255);
}
</style>
</head>
<body>
<!-- 2. 加强自定义菜单【√】
·单击鼠标右键的时候弹出自定义菜单(修身,齐家,治国,平天下)
·菜单项有点击时log一下菜单名称,之后菜单消失
·鼠标滑过哪个菜单项哪个菜单项高亮 -->
<ul>
<li id="Refresh">刷新(F5)</li>
<li>修身(s)</li>
<li>齐家(q)</li>
<li>治国(z)</li>
<li>平天下(p)</li>
</ul>
<script>
var ul = document.querySelector("ul")
var lis = document.querySelectorAll("li")
var F5 = document.getElementById("Refresh")
// var Rclick = document.oncontextmenu()
// 阻止浏览器的右键弹出列表的默认行为
document.addEventListener(
"contextmenu",
function(e){
e.preventDefault()
ul.style.display = "block"
ul.style.left = e.pageX + "px"
ul.style.top = e.pageY + "px"
}
)
// 实现点击li菜单项时log一下菜单名称,及鼠标滑过哪个菜单项哪个菜单项高亮
ul.addEventListener(
"click",
function(e){
if(e.target.nodeName === "LI"){
console.log(e.target.innerText);
ul.style.display = "none"
}
}
)
// 实现刷新按钮
F5.addEventListener(
"click",
function(e){
window.location.reload()
}
)
// 单击页面的任意位置关闭ul
document.addEventListener(
"click",
(e)=>{
ul.style.display = "none"
}
)
</script>
</body>
</html>边栏推荐
- Transactional事务传播行为?
- Introduction to FPGA (III) - 38 decoder
- Redisson分布式锁使用实例(一)
- Harbor2.2 quick check of user role permissions
- 连锁店收银系统如何帮助鞋店管理好分店?
- How much do you know about the two infrastructures of the badminton stadium?
- Redisson分布式锁流程详解(二)
- C language code quantity statistical tool
- [early knowledge of activities] list of recent activities of livevideostack
- 请问下有人知道FlinkSQL 的 Retrack 在哪里可以指定吗? 网上资料只看到API 代码设
猜你喜欢
随机推荐
美容院管理系统统一管理制度?
Use the jsonobject object in fastjason to simplify post request parameter passing
Beauty salon management system unified management system?
Codepoint 58880 not found in font, aborting. Flutter build APK reports an error
3.2 create menu and game pages (Part 2)
Audio and video+
SSJ-21B时间继电器
基于STM32的SIM900A发送中文和英文短信
Sword finger offer 25. merge two sorted linked lists
干货|语义网、Web3.0、Web3、元宇宙这些概念还傻傻分不清楚?(中)
How do children's playgrounds operate?
Redis为什么这么快?Redis的线程模型与Redis多线程
Digital intelligence transformation, management first | jnpf strives to build a "full life cycle management" platform
FPGA入门学习(二) - 二选一的选择器
Pytoch deep learning quick start tutorial -- mound tutorial notes (I)
Pytorch深度学习快速入门教程 -- 土堆教程笔记(二)
Audio and video technology development weekly | 255
三维点云课程(八)——特征点匹配
pytest接口自动化测试框架 | 通过标记表达式执行用例
Flutter JNI confusion introduction.So file release package flash back









