2024年07月23日 建站教程
功能介绍:屏蔽浏览器自带的右键菜单,自己定义一个配合自己页面的菜单,下面我们用window.oncontextmenu来定义一下!
1、css控制一下div
#menu {
position: absolute;
top: -500px;
z-index: 99999;
}
2、js可以直接用
window.oncontextmenu=function(e){
//取消默认的浏览器自带右键
e.preventDefault();
//获取我们自定义的右键菜单
var menu=document.getElementById('menu');
//根据事件对象中鼠标点击的位置,进行定位
menu.style.left=e.clientX+'px';
menu.style.top=e.clientY+'px';
if(window.screen.height == document.body.clientHeight){
$('#fullScreenName').html('退出全屏')
}else{
$('#fullScreenName').html('显示全屏')
}
}
本文链接:http://so.lmcjl.com/news/9005/