推荐一款右键菜单

先上图


contextmenu.gif

github连接

安装

yarn install / npm install

运行

npm run dev

使用

.icon-table{
  background: url('build/styles/images/table.png') no-repeat center;
}
// or
.icon-table:before{
  content: '';
  ...
}
// listener event
ContextMenu.on('itemclick', function (type, e, cmd) {
  console.log(arguments)
})
// bind comtextmenu event
document.querySelector('.somedom')
  .addEventListener('contextmenu', 
    function (e) {
      ContextMenu.show([
        { text : 'item-0', command: 'cmd-0', cls: 'icon-table' },
        '-',
        { 
          text: 'item-1', items: [
            { text: 'item-1-0', command: 'cmd-1-0', disabled: true },
            { text: 'item-1-1', command: 'cmd-1-1' }
          ]
        }
      ], e)
  })

接口一览

/*
 * 显示菜单
*/

ContextMenu.show(items: Array, e: Event): void


/*
 * 隐藏菜单
*/

ContextMenu.hide(): void


/*
 * 绑定事件
 * 提供了 itemclick 事件
*/

ContextMenu.on(event: String, hanler: Function): void


/*
 * 解除绑定
 * 提供了 itemclick 事件
*/

ContextMenu.off(event: String, hanler?: Function): void

猜你喜欢

转载自www.cnblogs.com/homehtml/p/12474606.html