开发者

Jquery - Context menu - rightclick

开发者 https://www.devze.com 2023-04-05 07:53 出处:网络
I use a plugin for jquery - ContextMenu. - http://abeautifulsite.net/blog/2008/09/jquery-context-menu-plugin/

I use a plugin for jquery - ContextMenu. - http://abeautifulsite.net/blog/2008/09/jquery-context-menu-plugin/

I have a div in the center of the page. I have the background-image in the points. I 开发者_JS百科need it to only using jquery rightclick on the background-image. If you click on the background-image, so I want to display the ContextMenu. If you click the div with id divPage, nothing Happens.

Thanks for the advice or Possibly another solution.

HTML

<body>
<form id="formBackground" method="post">
<ul id="myMenu" class="contextMenu">
                    <li class="insert"><a href="#insert">Add New</a></li>       
                    <li class="edit"><a href="#edit">Edit</a></li>                  
                    <li class="delete"><a href="#delete">Delete</a></li>            
                </ul>

    <div id="divPage">
Text.
    </div>
</form>

CSS

body, html {
height: 100%;
}

body{
padding: 0px;
margin: 0px;
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 12px;
color: white;
background-image: url('../images/backgrounds/bg.jpg');
background-repeat:no-repeat;
background-position:top;
}

div#divPage{
width: 800px;
height: 300px;
margin: auto;
}

JS

$('body').bind('mousedown', function (evt) {

                switch (evt.which) {       
            case 3:
            if(evt.target == $('body')[0]) {
                //Show context menu
            }
            break;
    }                

            });


I think you are over-complicating things.

Firstly I do not see your List anywhere in your code that creates the context menu.

Secondly all you need to do is:

$("idOfTheObjectYouWantToHaveAMenuOn").contextMenu({menu:"yourList"});


why not let the contextmenu pop up when the div itself is clicked? if you need to show up the menu only by clicking on the bg image you need to put the image in the div itself and style it so it acts like an bg image. you can do this with css z-index and position absolute

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号