Jquery short right-click menu multi-browser compatibility _ jquery

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.