当前位置:网站首页>Customize browser default right-click menu bar
Customize browser default right-click menu bar
2022-07-26 12:14:00 【Good at learning】
This article briefly introduces How to change the browser's default right-click menu bar
Right click anywhere on the page , Customized menus will be displayed according to the click position of the mouse
design sketch :

Don't talk much , Go straight to the code !
<!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> Enhanced custom menu </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 " Song style ";
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. Enhanced custom menu 【√】
· When you click the right mouse button, a custom menu pops up ( Cultivate one's morality , To put , Governing the , Flat world )
· When the menu item is clicked log Check the menu name , After the menu... Disappears
· Which menu item is highlighted when the mouse is over -->
<ul>
<li id="Refresh"> Refresh (F5)</li>
<li> Cultivate one's morality (s)</li>
<li> To put (q)</li>
<li> Governing the (z)</li>
<li> Flat world (p)</li>
</ul>
<script>
var ul = document.querySelector("ul")
var lis = document.querySelectorAll("li")
var F5 = document.getElementById("Refresh")
// var Rclick = document.oncontextmenu()
// Block the default behavior of the browser's right-click pop-up list
document.addEventListener(
"contextmenu",
function(e){
e.preventDefault()
ul.style.display = "block"
ul.style.left = e.pageX + "px"
ul.style.top = e.pageY + "px"
}
)
// Achieve click li Menu item log Check the menu name , And which menu item the mouse is over, which menu item is highlighted
ul.addEventListener(
"click",
function(e){
if(e.target.nodeName === "LI"){
console.log(e.target.innerText);
ul.style.display = "none"
}
}
)
// Implement refresh button
F5.addEventListener(
"click",
function(e){
window.location.reload()
}
)
// Click anywhere on the page to close ul
document.addEventListener(
"click",
(e)=>{
ul.style.display = "none"
}
)
</script>
</body>
</html>边栏推荐
- Flink cdc 是不是只支持 sql-client的方式提交SQL脚本啊
- X.509、PKCS文件格式介绍
- Pytest interface automation test framework | execute use cases through markup expressions
- Is it easy to find a job after programmer training?
- QT入门引导 及其 案例讲解
- FPGA入门学习(二) - 二选一的选择器
- Flink's real-time data analysis practice in iFLYTEK AI marketing business
- 剑指 Offer 24. 反转链表
- Redisson分布式锁使用实例(一)
- pytest接口自动化测试框架 | pytest常用插件
猜你喜欢

一些常用的文章写作使用方法和技巧

DS-112时间继电器

【Map】万能的Map使用方法 & 模糊查询的两种方式

美容院管理系统统一管理制度?

How does the chain store cashier system help shoe stores manage their branches?

Hou Peixin, chairman of the openharmony Working Committee of the open atom open source foundation, sent a message to the openatom openharmony sub forum

Redis master-slave replication principle

How RFID works
2022就业季!Adobe助力创意产业工作者,突破技能桎梏,回归能力本源

pytest接口自动化测试框架 | pytest配置文件
随机推荐
Pytorch深度学习快速入门教程 -- 土堆教程笔记(一)
11 "pocket" universities in China! Running on campus and leaving the school before accelerating
代码实例详解【可重入锁】和【不可重入锁】区别?
以太网驱动详解之RMII、SMII、GMII、RGMII接口
JVM内存溢出和内存泄漏的区别
【Mysql约束】
FPGA入门学习(一) - 第一个FPGA工程
What is per title encoding?
pytest接口自动化测试框架 | conftest.py
2022.7.23-----leetcode.剑指offer.115
Pytest interface automated testing framework | using multiple fixtures
三维点云课程(八)——特征点匹配
Oracle的Windows版本能在linux中使用吗?
物联网设备加密的意义
X.509、PKCS文件格式介绍
SSJ-21B时间继电器
动静态库的实现(打包动静态库供他人使用)
Introduction to FPGA (III) - 38 decoder
Redis实现Single单点登入--系统框架搭建(一)
pytest接口自动化测试框架 | 重新运行失败用例