Home  >  Article  >  Web Front-end  >  Detailed example of bootstrap using dropdown-menu to implement context menu

Detailed example of bootstrap using dropdown-menu to implement context menu

小云云
小云云Original
2017-12-27 11:04:582489browse

This article mainly introduces the relevant information about using dropdown-menu to implement context menu in bootstrap. I hope this article can help everyone. Friends who need it can refer to it. I hope it can help everyone.

Detailed explanation of bootstrap using dropdown-menu to implement context menu

Written in front:

The so-called context menu, its difference from the general menu It lies in:

Triggered by right-clicking and displayed at the right-click location of the mouse

After the mouse is clicked elsewhere, the menu disappears

Implementation method:

Define an ordinary dropdown-menu without trigger conditions in HTML, and then write the monitoring of the parent container of this menu to achieve this.

Code:


##


$("#settingInGraph").mousedown(function(e) { 
if (3 == e.which) { 
     document.oncontextmenu = function() {return false;} 
     $("#contextMenu").hide(); 
     $("#contextMenu").attr("style","display: block; position: fixed; top:" 
     + e.pageY 
     + "px; left:" 
     + e.pageX 
     + "px; width: 180px;"); 
     $("#contextMenu").show(); 
     } 
}); 
$("#settingInGraph").click(function(e) { 
$("#contextMenu").hide();              });

Related recommendations:


Examples to explain the responsive framework Bootstrap grid system

Bootstrap tree control usage experience sharing

Examples to explain the bootstrap paginator paging plug-in Two ways to use

The above is the detailed content of Detailed example of bootstrap using dropdown-menu to implement context menu. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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