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. 《Qt Quick 4小时入门》学习笔记

    http://edu.csdn.net/course/detail/1042/14804?auto_start=1   Qt Quick 4小时入门 第五章:Qt Quick里的信号与槽   QML中 ...

  2. WPF中找不到Image或者Image不是Drawing系列

    WPF中默认没有引用WinForm里面的一些东西,都是用它自带的那一套,但又不能完全脱离,所以有的时候比较蛋疼

  3. MVVM模式下,ViewModel和View,Model有什么区别

    摘自正美的5群 Model:很简单,就是业务逻辑相关的数据对象,通常从数据库映射而来,我们可以说是与数据库对应的model. View:也很简单,就是展现出来的用户界面. 基本上,绝大多数软件所做的工 ...

  4. 暴雪HASH算法(转)

    暴雪公司有个经典的字符串的hash公式 先提一个简单的问题,假如有一个庞大的字符串数组,然后给你一个单独的字符串,让你从这个数组中查找是否有这个字符串并找到它,你会怎么做? 有一个方法最简单,老老实实 ...

  5. 理解CSS中的数学表达式calc()

    前面的话 数学表达式calc()是CSS中的函数,主要用于数学运算.使用calc()为页面元素布局提供了便利和新的思路.本文将介绍calc()的相关内容 定义 数学表达式calc()是calculat ...

  6. Yii2的深入学习--别名(Aliases)

    在之前自动加载机制的文章中,我们有提到别名,提到 getAlias 方法,大家当时可能不太清楚,这到底是什么,今天我们就来说一下别名. 别名用来表示文件路径和 URL,这样就避免了将一些文件路径.UR ...

  7. 利用Microsoft.Office.Interop.Excel 将web页面转成PDF

    网上有很多将Web页面转成PDF的方法,还有许多收费的第三方插件.其实利用Office 自带的将EXCEL发布成PDF的功能就可以实现,如果你的需求没有多复杂,可以采用笔者的方法. 首先将web页面h ...

  8. HTML5移动Web开发(二)——配置移动开发环境以及简单示例

    一.准备 1.配置本地网络服务.对于Windows.Mac和Linux,最容易的方法是使用免费的XAMPP软件:http://www.apachefriends.org/en/index.html X ...

  9. Spark入门实战系列--2.Spark编译与部署(下)--Spark编译安装

    [注]该系列文章以及使用到安装包/测试数据 可以在<倾情大奉送--Spark入门实战系列>获取 .编译Spark .时间不一样,SBT是白天编译,Maven是深夜进行的,获取依赖包速度不同 ...

  10. 初探JavaScript(一)——也谈元素节点、属性节点、文本节点

    Javascript大行其道的时候,怎么能少了我来凑凑热闹^_^ 基本上自己对于js的知识储备很少,先前有用过JQuery实现一些简单功能,要论起JS的前世今生,来龙去脉,我就一小白.抱起一本< ...