简体   繁体   中英

right click context menu jquery

Does anybody have any code for a jquery context menu? Just need a div popup at pointer position when right mouse button pressed.

Here is what I found:

Right Click Context Menu Using Jquery and asp.net - Code Project Article

Plugins tagged Right Click Menu on Jquery website

Interestingly, the dogo library has a standard set of UI widgets , and the context menu is part of that standard UI set. (The dojo library is nice and pretty with a standard look)

Dojo is a separate javascript library just like JQuery. Not sure how completely compatible dojo is with jquery, but there are ways to get them both working together if you want to.

Lord Google gave me most of the answers ;)


Similar SO questions that might be helpful:
jQuery Right-Click Context Menu Help!
jquery context menu plugin - Where is the right click event type?
JavaScript: Capturing right click and disabling menu only within certain element

这是一个插件: jQuery Context Menu

您可以使用的另一个插件是我开发的一个名为Audero Context Menu的插件。

This can easily be achieved by using the event listener in jQuery, here is a clean and fast way of doing it:

 //Now add the jQuery $(document).ready(function() { //Just starting up here var menu = $('.menu');//get the menu $(document).on('contextmenu', function(e) {//What this does is simply; if right-click, run function(contains an event) e.preventDefault();//Prevent the default action: the normal right-click-menu to show menu.css({ display: 'block',//show the menu top: e.pageY,//make the menu be where you click (y) left: e.pageX//make the menu be where you click (x) }); }); $(document).click(function() { //When you left-click menu.css({ display: 'none' });//Hide the menu }); }); 
 /* just some css to display it */ .menu { background: #fff; width: 60px; padding: 3px 10px; box-shadow: 0 0 10px -3px rgba(0, 0, 0, .3); border: 1px solid #ccc; display: none; position: absolute;//this is important } 
 <!-- jQuery CDN --><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <!-- Add some HTML for the menu --> <div class="menu"> <p>Option 1</p> <p>Option 2</p> </div> 

 <!DOCTYPE html> <html> <head> <title>Right Click</title> <link href="https://swisnl.github.io/jQuery-contextMenu/dist/jquery.contextMenu.css" rel="stylesheet" type="text/css" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script src="https://swisnl.github.io/jQuery-contextMenu/dist/jquery.contextMenu.js" type="text/javascript"></script> <script src="https://swisnl.github.io/jQuery-contextMenu/dist/jquery.ui.position.min.js" type="text/javascript"></script> </head> <body> <span class="context-menu-one" style="border:solid 1px black; padding:5px;">Right Click Me</span> <script type="text/javascript"> $(function() { $.contextMenu({ selector: '.context-menu-one', callback: function(key, options) { var m = "clicked: " + key; window.console && console.log(m) || alert(m); }, items: { "edit": {name: "Edit", icon: "edit"}, "cut": {name: "Cut", icon: "cut"}, copy: {name: "Copy", icon: "copy"}, "paste": {name: "Paste", icon: "paste"}, "delete": {name: "Delete", icon: "delete"}, "sep1": "---------", "quit": {name: "Quit", icon: function(){ return 'context-menu-icon context-menu-icon-quit'; }} } }); $('.context-menu-one').on('click', function(e){ console.log('clicked', this); }) }); </script> </body> </html> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM