当前位置:网站首页>鼠标右键 自定义
鼠标右键 自定义
2022-07-06 18:02:00 【阿六啊】

1.在需要添加右键的页面,绑定contextmenu事件(阻止浏览器默认事件,添加自定义事件)
<xx组件 @contextmenu.prevent.native="openMenu($event)">
2.在页面编写右键菜单的内容
<ul
v-show="visible"
:style="contextmenuStyle"
class="contextmenu"
>
<li @click="setBack">
置于底层
</li>
<li @click="setTop">
置于顶层
</li>
</ul>
3.定义属性变量
private contextmenuStyle: any={
}
private visible=false;
4.创建监听事件,来触发关闭右键菜单的方法
@Watch('visible')
private visibleChange () {
if (this.visible) {
// 显示的时候 添加一个点击事件 用于隐藏右键的内容
window.addEventListener('click', this.closeMenu);
} else {
window.removeEventListener('click', this.closeMenu);
}
}
5.打开和关闭右键菜单的两个方法
// 鼠标右键
private async openMenu (e) {
this.contextmenuStyle = {
left: e.offsetX + 'px',
top: e.offsetY + 'px'
};
this.visible = true;
}
private setBack () {
this.drawer.sendToBack();
}
private setTop () {
this.drawer.setTop();
}
private closeMenu () {
this.visible = false;
}
6.样式
<style lang='scss' scoped>
@import '[email protected]/css/variable';
.contextmenu {
margin: 0;
background: #eeeded;
opacity: 0.9;
z-index: 3000;
position: absolute;
list-style-type: none;
padding: 5px;
border-radius: 4px;
font-size: 12px;
color: #505050;
border: 1px solid $color-border;
box-shadow: 2px 2px 3px 0 rgba(0, 0, 0, 0.3);
}
.contextmenu li {
margin: 0;
padding: 2px 10px;
border-radius: 2px;
cursor: pointer;
}
.contextmenu li:hover {
background: $color-button-disabled-hover;
color: $color-basic;
}
</style>
边栏推荐
- Machine learning: the difference between random gradient descent (SGD) and gradient descent (GD) and code implementation.
- 安利一波C2工具
- [advanced C language] 8 written questions of pointer
- AcWing 346. 走廊泼水节 题解(推公式、最小生成树)
- 安全保护能力是什么意思?等保不同级别保护能力分别是怎样?
- JTAG principle of arm bare board debugging
- docker 方法安装mysql
- 736. Lisp 语法解析 : DFS 模拟题
- Go zero micro service practical series (IX. ultimate optimization of seckill performance)
- 子网划分、构造超网 典型题
猜你喜欢

黑马笔记---创建不可变集合与Stream流

Body mass index program, entry to write dead applet project

Make Jar, Not War

【信号与系统】

LeetCode. 剑指offer 62. 圆圈中最后剩下的数

C language - array

Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform

LeetCode:1175. 质数排列

字节P7专业级讲解:接口测试常用工具及测试方法,福利文

2022 Google CTF SEGFAULT LABYRINTH wp
随机推荐
增加 pdf 标题浮窗
AI automatically generates annotation documents from code
【C语言进阶篇】指针的8道笔试题
What does front-end processor mean? What is the main function? What is the difference with fortress machine?
How to evaluate load balancing performance parameters?
Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
What are the differences between Oracle Linux and CentOS?
Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
uva 1401 dp+Trie
Installation and testing of pyflink
AcWing 1142. 繁忙的都市 题解(最小生成树)
让我们,从头到尾,通透网络I/O模型
Meet in the middle
Js逆向——捅了【马蜂窝】的ob混淆与加速乐
curl 命令
从零开始匹配vim(0)——vimscript 简介
Spark TPCDS Data Gen
[signal and system]
ClickHouse字段分组聚合、按照任意时间段粒度查询SQL
HMM 笔记