jquery 右键菜单实现

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8" />
        <title></title>
        <link rel="stylesheet" href="css/contextMenu.css" />
        <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
        <script src="js/jquery.contextMenu.min.js"></script>
        <style>
            body {
                background: #000;
            }
            
            .container {
                width: 1000px;
                height: 720px;
                position: absolute;
                left: 50%;
                margin: 100px 0 0 -500px;
            }
            
            .container .box {
                width: 46%;
                height: 100%;
                background: #eee;
            }
            
            #box1 {
                float: left;
            }
            
            #box2 {
                float: right;
            }
            
            .title {
                height: 50px;
                line-height: 50px;
                font-size: 24px;
                text-align: center;
            }
            
            pre {
                font-size: 12px;
                font-family: "微软雅黑";
            }
        </style>
    </head>

    <body>
        <div class="container">
            <div id="box1" class="box">
                <div class="title">右键点我!</div>
                <pre>
                $("#box1").contextMenu({
                    menu: [{
                            text: "新增",
                            callback: function() {
                                alert("新增");
                            }
                        },
                        {
                            text: "复制",
                            callback: function() {
                                alert("复制");
                            }
                        },
                        {
                            text: "粘贴",
                            callback: function() {
                                alert("粘贴");
                            }
                        },
                        {
                            text: "删除",
                            callback: function() {
                                alert("删除");
                            }
                        }
                    ]
                });    
                </pre>
            </div>
            <div id="box2" class="box">
                <div class="title">右键点我!</div>
                <pre>
            $("#box2").contextMenu({
                width: 110,// width
                itemHeight: 30,// 菜单项height
                bgColor: "#333",// 背景颜色
                color: "#fff",// 字体颜色
                fontSize: 12,// 字体大小
                hoverBgColor: "#99CC66",// hover背景颜色
                target: function(ele) {// 当前元素
                    console.log(ele);
                },
                menu: [{// 菜单项
                        text: "新增",
                        icon: "img/add.png",
                        callback: function() {
                            alert("新增");
                        }
                    },
                    {
                        text: "复制",
                        icon: "img/copy.png",
                        callback: function() {
                            alert("复制");
                        }
                    },
                    {
                        text: "粘贴",
                        icon: "img/paste.png",
                        callback: function() {
                            alert("粘贴");
                        }
                    },
                    {
                        text: "删除",
                        icon: "img/del.png",
                        callback: function() {
                            alert("删除");
                        }
                    }
                ]
            
            });
                    </pre>
            </div>
        </div>
        <script>
            $("#box1").contextMenu({
                menu: [{
                        text: "新增",
                        callback: function() {
                            alert("新增");
                        }
                    },
                    {
                        text: "复制",
                        callback: function() {
                            alert("复制");
                        }
                    },
                    {
                        text: "粘贴",
                        callback: function() {
                            alert("粘贴");
                        }
                    },
                    {
                        text: "删除",
                        callback: function() {
                            alert("删除");
                        }
                    }
                ]
            });

            $("#box2").contextMenu({
                width: 110, // width
                itemHeight: 30, // 菜单项height
                bgColor: "#333", // 背景颜色
                color: "#fff", // 字体颜色
                fontSize: 12, // 字体大小
                hoverBgColor: "#99CC66", // hover背景颜色
                target: function(ele) { // 当前元素
                    console.log(ele);
                },
                menu: [{ // 菜单项
                        text: "新增",
                        icon: "img/add.png",
                        callback: function() {
                            alert("新增");
                        }
                    },
                    {
                        text: "复制",
                        icon: "img/copy.png",
                        callback: function() {
                            alert("复制");
                        }
                    },
                    {
                        text: "粘贴",
                        icon: "img/paste.png",
                        callback: function() {
                            alert("粘贴");
                        }
                    },
                    {
                        text: "删除",
                        icon: "img/del.png",
                        callback: function() {
                            alert("删除");
                        }
                    }
                ]

            });
        </script>
    </body>

</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值