Use JavaScript to customize right-click menus under Bootstrap __java

Source: Internet
Author: User

In fact, do not Bootstrap also do, purely for good-looking ...

The first thing to do is to screen out the browser's default right-click menu where you need to pop the right button:

<div id= "Rightmenuparentdiv" oncontextmenu= "ShowMenu (); return false;" >
    <div id= "Rightmenudiv" >
        123
    </div>
</div>

Then write ShowMenu this function:

function ShowMenu () {
            document.getElementById ("tree"). onmousedown = function (e) {
                if (E.which = = 3) {
                    if (!e ) {
                        e = window.event;
                    } else {
                        e.srcelement = e.target;
                    }
                    if (e.srcelement.innerhtml!= "") {
                        document.getElementById ("Rightmenu"). Style.left = E.clientx + "px";
                        document.getElementById ("Rightmenu"). Style.top = E.clienty + "px";
                        document.getElementById ("Rightmenu"). Style.display = "Block";}}}
        
Write the right button in the Body menu:
<div class= "Panel Panel-default" style= "position:absolute;display:none;z-index:999;padding:0;margin:0; line-height:0 "id=" Rightmenu "> <div class=" panel-body "style=" margin:0;padding:0
    ; >
            <ul class= "nav nav-pills nav-stacked" >
                <li><a href= "#" > I heard I was the first menu item </a></li >
                <li><a href= "#" > I am the second menu item </a></li>
                <li><a href= "#" > I'm the last one. </a ></li>
            </ul>
    </div>
</div>
Here are some CSS styles in the bootstrap.
In order for the menu to disappear in time, you need to add a function to the javascript:

function Hiddenrightmenu () {
            document.getElementById ("Rightmenu"). Style.display = "None";
        }
and add it to the body tag:
<body onclick= "Hiddenrightmenu ();" >
</body>
This allows the right-click menu to pop up and hide it in time.

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.