ContextJS is a lightweight solution for contextual menus. Currently, there are two versions.

The first is to be used with Twitters Bootstrap   (bootstrap.css specifically). If you do not use or want to use bootstrap.css, there is a standalone stylesheet to give the menu it's base styles.

Features

  • Linted: Valid JS
  • Can be used with or without Twitters Bootstrap.css
  • Event Based Links
  • Anchor Links
  • Headers
  • Dividers
  • Recursive Menus (infinite depth)
  • Vertical Space Detection (turns into a "dropup")
  • Horizontal Space Detection (Drops to the left instead of right)
  • Add/Delete menus Dynamically

在线实例

实例演示

使用方法

  1. context.init({
  2. fadeSpeed: 100,
  3. filter: function ($obj){},
  4. above: 'auto',
  5. preventDoubleContext: true,
  6. compress: false
  7. });
复制

Headers

  1. {
  2. header: 'My Header Title'
  3. }
复制

Anchor Links

  1. {
  2. text: 'My Link Title',
  3. href: 'http://contextjs.com/',
  4. target: '_blank'
  5. }
复制

Dividers

  1. {
  2. divider: true
  3. }
复制

Event Based Actions

  1. {
  2. text: 'Event Based Link',
  3. action: function(e){
  4. e.preventDefault();
  5. alert('Do Something');
  6. }
  7. }
复制

Sub-Menus

  1. {
  2. text: 'My Sub-menu',
  3. subMenu: [menuObjects]
  4. }
复制

Tracking Links with Google Analytics

  1. {
  2. text: 'context.js',
  3. href: 'http://contextjs.com/context.js',
  4. target:'_blank',
  5. action: function(e){
  6. _gaq.push(['_trackEvent', 'ContextJS Download', this.pathname, this.innerHTML]);
  7. }
  8. }
复制

参数详解

Paramater Type Default Description
fadeSpeed int 100 The speed in which the context menu fades in (in milliseconds)
filter function null Function that each finished list element will pass through for extra modification.
above string || boolean 'auto' If set to 'auto', menu will appear as a "dropup" if there is not enough room below it. Settings to true will make the menu a "popup" by default.
preventDoubleContext boolean true If set to true, browser-based context menus will not work on contextjs menus.
compress boolean false If set to true, context menus will have less padding, making them (hopefully) more unobtrusive

Updating Settings

  1. context.settings({initSettings});
复制
Paramater Type Default Description
settings object null The init settings can be placed in here to update context menus written to the DOM. Changing settings between attaching menus will give the menus their own options.

Attaching

  1. context.attach('#download', [menuObjects]);
复制
Paramater Type Default Description
selector string null The jQuery (or css) selector of the element you want to apply the context menu to
menuObjects array null An array of objects that define the menus structure

Destroying

  1. context.destroy('#download');
复制
Paramater Type Default Description
selector string null The jQuery (or css) selector of the element you want to remove the context menu from

Context.js 右键菜单的更多相关文章

  1. js 右键菜单

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  2. ASP.NET Boilerplate 学习 AspNet Core2 浏览器缓存使用 c#基础,单线程,跨线程访问和线程带参数 wpf 禁用启用webbroswer右键菜单 EF Core 2.0使用MsSql/MySql实现DB First和Code First ASP.NET Core部署到Windows IIS QRCode.js:使用 JavaScript 生成

    ASP.NET Boilerplate 学习   1.在http://www.aspnetboilerplate.com/Templates 网站下载ABP模版 2.解压后打开解决方案,解决方案目录: ...

  3. JS组件系列——Bootstrap右键菜单解决方案:ContextMenu

    前言:有段时间没发表随笔了,过个年人都变得懒了.新年刚来上班,今天正好得空,将去年遗留的两个小组件总结记录下.有朋友跟我说:你的bootstrap组件要能够形成一个可以满足一般项目需求的系列组件,才有 ...

  4. js屏蔽浏览器右键菜单,粘贴,复制,剪切,选中(转)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. js实现自定义右键菜单--兼容IE、Firefox、Chrome

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  6. 关于FlexPaper 2.1.2版本 二次开发 Logo 、打印、搜索、缩略图、添加按钮、js交互、右键菜单、书签等相关问题

    2015-03-02 更新文章,由于需求修改,更改了flexpaper插件,故增加第9.10.11小节,下载代码时请注意. 先废话几句.最近用到文档在线浏览功能,之前用的是print2flash(一个 ...

  7. js禁止页面复制 禁用页面右键菜单的代码

    js实现禁止页面复制功能.禁用页面右键菜单等功能.  <body oncontextmenu="return false">禁用网页右键菜单,但是仍然可以使用快捷键复制 ...

  8. js禁止默认的右键菜单或出现自定义右键菜单

    1.屏蔽默认的右键菜单 js: document.getElementById('myimg').oncontextmenu=function(){return false;} jquery: $(' ...

  9. 禁止页面复制功能 js禁止复制 禁用页面右键菜单

    <body oncontextmenu="return false">禁用网页右键菜单,但是仍然可以使用快捷键复制. js代码禁用复制功能: <script  t ...

随机推荐

  1. AngularJs单元测试

    这篇文章主要介绍了angularJS中的单元测试实例,本文主要介绍利用Karma和Jasmine来进行ng模块的单元测试,并用Istanbul  来生成代码覆盖率测试报告,需要的朋友们可以参考下,以下 ...

  2. 牛刀小试:使用Reactive Extensions(Rx),对短时间内多次发生的事件限流

    我之前有一篇文章介绍到了Reactive Extension这个组件,请参考下面的文章,其中有一些基本的概念和相关的链接 牛刀小试:使用Reactive Extensions(Rx),一行代码实现多线 ...

  3. JavaScript的学习--生成二维码

    有一些耗cpu的计算,完全可以在客户端上计算,比如生成二维码. qrcode其实是通过计算,然后使用jquery实现图形渲染和画图.支持canvas和table两种方式生成我们所需的二维码. 具体用法 ...

  4. PHP将部分内容替换成星号

    在最近的项目中,会碰到到某人的手机号码隐藏中间几位,身份证号码只显示末尾4位的需求.当时一开始是网上搜索了一下,看到有人是用substr_replace这个函数来替换的,后面我也用了这个函数,但在用的 ...

  5. HTML5移动Web开发(六)——定义一个内容策略

    通过分析工具搜集到的数据,你可以定义一个内容策略,这对已经有了一个桌面网站的人是非常有用的. 1.确认你已经把分析工具的Javascript代码嵌入到网站中.(http://www.cnblogs.c ...

  6. oracle数据库字符集US7ASCII,在java中处理中文问题

    原来项目中oracle数据库一直是US7ASCII,我新项目对接的时候,查询以及插入中文,出现乱码问题. 暂时未能解决此问题,最终决定每次转码: 查询的时候: List<Record> l ...

  7. ADO.NET基础巩固-----连接类和非连接类

          最近的一段时间自己的状态还是不错的,早上,跑步,上自习看书,下午宿舍里面编程实战,晚上要么练习代码,要么去打球(在不打就没机会了),生活还是挺丰富的. 关于C#的基础回顾就先到前面哪里,这 ...

  8. 安装windows系统的installutil

    /// 该服务必须在它可以执行之前安装.    /// 服务的安装和卸载“installutil.exe”“installutil.exe / U”的服务可执行文件作为最后一个参数.    ///  ...

  9. Autofac - 组件

    快到年终了, 最近项目比较悠闲, 就想总结下, 项目中所使用到的一些技术, 以及使用方法. 之前有写过Dapper以及Dapper的一个扩展, 这些也是项目中使用过的. 算是一个温故而知新吧. 代码: ...

  10. Mac下Vim配置语法高亮

    设置终端的字体颜色 如图,打开终端然后,选择偏好设置,再选择描述文件,再窗口左侧可以选择系统配置好的,或者你也可以自定义,最后别忘了把你的配置设置成默认就行 Vim语法高亮设置 只需要找到vimrc配 ...