ca888会员登录几个实用的jQuery技术

2019-05-15 03:34栏目:ca888圈内

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

Context.js 右键菜单,context.js右键菜单

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.

1)禁用右键单击功能 如果你想为用户保护网站信息,那么开发者可以使用这段代码——禁用右键单击功能。

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

复制代码 代码如下:

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. });

复制

$(document).ready(function() {
 //catch the right-click context menu
 $(document).bind("contextmenu",function(e) {    
  //warning prompt - optional
  alert("No right-clicking!");

在线实例

实例演示

使用方法

  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. }

复制

  //delete the default context menu
  return false;
 });
});

Headers

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

复制

Anchor Links

  1. {
  2. text: 'My Link Title', 
  3. href: '', 
  4. target: '_blank'
  5. }

复制

2)使用jQuery设定文本大小 使用这段代码,用户可根据需求重新设定文本尺寸(增加或减少)。

Anchor Links

  1. {
  2. text: 'My Link Title', 
  3. href: '', 
  4. target: '_blank'
  5. }

复制

Dividers

  1. {
  2. divider: true
  3. }

复制

复制代码 代码如下:

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. }

复制

$(document).ready(function() {
 //find the current font size
 var originalFontSize = $('html').css('font-size');

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. }

复制

 //Increase the text size
 $(".increaseFont").click(function() {
  var currentFontSize = $('html').css('font-size');
  var currentFontSizeNumber = parseFloat(currentFontSize, 10);

Sub-Menus

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

复制

Tracking Links with Google Analytics

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

复制

  var newFontSize = currentFontSizeNumber*1.2;
  $('html').css('font-size', newFontSize);
  return false;
 });

Tracking Links with Google Analytics

  1. {
  2. text: 'context.js', 
  3. href: '', 
  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

 

 //Decrease the Text Size
 $(".decreaseFont").click(function() {
  var currentFontSize = $('html').css('font-size');
  var currentFontSizeNum = parseFloat(currentFontSize, 10);

参数详解

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.

 

  var newFontSize = currentFontSizeNum*0.8;
  $('html').css('font-size', newFontSize);
  return false;
 });

版权声明:本文由ca888发布于ca888圈内,转载请注明出处:ca888会员登录几个实用的jQuery技术