Jquery short right-click menu compatible with ie6ie7ie8firefoxchrome
The Code is as follows:
$ (Function (){
Document. oncontextmenu = function () {return false;} // right-click to block
Document. onmousemove = mouseMove; // record the mouse position
});
Var mx = 0, my = 0;
Function mouseMove (ev) {Ev = ev | window. event; var mousePos = mouseCoords (Ev); mx = mousePos. x; my = mousePos. y ;}
Function mouseCoords (ev ){
If (ev. pageX | ev. pageY) {return {x: ev. pageX, y: ev. pageY };}
Return {x: ev. clientX, y: ev. clientY + $ (document). scrollTop ()};
}
$. Fn. extend ({RightMenu: function (id, options) {options = $. extend ({menuList: []}, options); var menuCount = options. menuList. length;
If (! $ ("#" + Id) [0]) {
Var pMenuList ="
";
For (var I = 0; I PMenuList + ="
- "+ Options. menuList [I]. menuName +"
";
}
PMenuList + ="
";
$ ("Body"). append (pMenuList). find ("#" + id). hide (). find ("li ")
. Bind ("mouseover", function () {$ (this). addClass ("RM_mouseover ");})
. Bind ("mouseout", function () {$ (this). removeClass ("RM_mouseover ");});
$ (Document). click (function () {$ ("#" + id). hide ();});
}
Return this. each (function (){
This. oncontextmenu = function (){
/* Move the cursor to the rightmost or rightmost side of the page to prevent scroll bars {*/
Var mw = $ ('body'). width (), mhh = $ ('html'). height (), mbh = $ ('body'). height (),
W = $ ('#' + id). width (), h = $ ('#' + id). height (),
Mh = (mhh> mbh )? Mhh: mbh; // the maximum height of the html and body
If (mh If (mw /*} You can also skip this step */
$ ("#" Incluid).hide().css ({top: my, left: mx}). show ();
}
});
}
});
Online demonstration right-click test results
Package download