Home > Web Front-end > JS Tutorial > body text

jquery implements display of custom right-click menu effect in specified area of ​​web page

PHPz
Release: 2018-09-29 10:03:48
forward
1182 people have browsed it

This article mainly introduces jquery to realize the custom right-click menu effect in a designated area of ​​​​the web page, involving jquery mouse clicks and event binding and other related techniques. It has certain reference value. Friends in need can refer to it, as follows:

This is a webpage right-click menu effect implemented by jquery. The difference from other customized right-click menus is that this menu is only valid within the specified area. If it exceeds the specified area, it will be displayed after right-clicking. It's still the browser's right-click menu. After running the effect, please right-click the mouse in the orange area, and a custom right-click menu with an icon will pop up, which is completely different from the browser's right-click menu!

A screenshot of the running effect is as follows:

The online demo address is as follows:

http://demo.jb51.net/ js/2015/jquery-web-area-right-click-menu-codes/

The specific codes are as follows:

<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery自定义区域的鼠标右键菜单</title>
<script src="jquery-1.6.2.min.js"></script>
<style type="text/css">
#mask{position: absolute;left: 0;top: 0;z-index: 9000;display: block;}
#myMenu{position: absolute;display: none;z-index: 9999;background: yellow;border: 1px solid;width: 200px;height: 155px;}
#textbox{background: orange;width: 380px;border: 2px solid;}
img{height: 30px;width: 30px;}
td{font-size: 20px;cursor: pointer;}
a{text-decoration: none;color: black;}
a: hover{color: white;background: black;}
</style>
<script type="text/javascript">
var windowwidth;
var windowheight;
var checkmenu;
$(window).ready(function() {
 $(&#39;#myMenu&#39;).hide();
  $(&#39;#textbox&#39;).bind("contextmenu",function(e){
  windowwidth = $(window).width();
  windowheight = $(window).height();
  checkmenu = 1;
  $(&#39;#mask&#39;).css({
  &#39;height&#39;: windowheight,
  &#39;width&#39;: windowwidth
  });
  $(&#39;#myMenu&#39;).show(500); 
    $(&#39;#myMenu&#39;).css({
    &#39;top&#39;:e.pageY+&#39;px&#39;,
    &#39;left&#39;:e.pageX+&#39;px&#39;
    });
    return false;
 });
$(&#39;#mask&#39;).click(function(){
$(this).height(0);
$(this).width(0);
$(&#39;#myMenu&#39;).hide(500);
checkmenu = 0;
return false;
});
$(&#39;#mask&#39;).bind("contextmenu",function(){
$(this).height(0);
$(this).width(0);
$(&#39;#myMenu&#39;).hide(500);
checkmenu = 0;
return false;
});
$(window).resize(function(){
if(checkmenu == 1) {
windowwidth = $(window).width();
 windowheight = $(window).height();
 $(&#39;#mask&#39;).css({
 &#39;height&#39;: windowheight,
 &#39;width&#39;: windowwidth,
 });
}
});
});
</script>
</head>
<body >
<p id="myMenu" >
<table cellspace="3">
<tr>
<td ><img src="images/twitter.png" ></td><td><a href="#">tweet me</a></td>
</tr>
<tr>
<td ><img src="images/facebook.png" > </td><td><a href="#">facebook share</a></td>
</tr>
<tr>
<td ><img src="images/myspace.png" > </td><td><a href="#">myspace share</a></td>
</tr>
<tr>
<td ><img src="images/mail.png" > </td><td><a href="#">e-mail this</a></td>
</tr>
</table>
</p>
<p id="mask"> </p>
<p id="textbox">
<p>嗨!您好,在这个区域内点击您的鼠标右键吧,会弹出一个自定义的右键菜单,和浏览器的右键菜单完全不一样哦!<p/>
 </p>
 <p>
</body>
</html>
Copy after login

The above is the entire content of this chapter, more related For tutorials, please visit jQuery Video Tutorial!

Related labels:
source:jb51.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template