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() { $('#myMenu').hide(); $('#textbox').bind("contextmenu",function(e){ windowwidth = $(window).width(); windowheight = $(window).height(); checkmenu = 1; $('#mask').css({ 'height': windowheight, 'width': windowwidth }); $('#myMenu').show(500); $('#myMenu').css({ 'top':e.pageY+'px', 'left':e.pageX+'px' }); return false; }); $('#mask').click(function(){ $(this).height(0); $(this).width(0); $('#myMenu').hide(500); checkmenu = 0; return false; }); $('#mask').bind("contextmenu",function(){ $(this).height(0); $(this).width(0); $('#myMenu').hide(500); checkmenu = 0; return false; }); $(window).resize(function(){ if(checkmenu == 1) { windowwidth = $(window).width(); windowheight = $(window).height(); $('#mask').css({ 'height': windowheight, 'width': 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>
The above is the entire content of this chapter, more related For tutorials, please visit jQuery Video Tutorial!