当前位置: 首页 > 图文教程 > 网络编程 > Javascript > jQuery 页面 Mask实现代码

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 jQuery 页面 Mask实现代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 412 ::
收藏到网摘: n/a

何为页面 Mask (遮罩)?看过 jQuery 的 Lightbox 插件的一定不会陌生。就是在页面上建一个透明层遮盖住页面的全部内部。 在 Ajax 应用中,显示一个 Dialog(以 Div 方式显示)前,都会先建一个 Mask。因为经常会用到,所以写成了一个 jQuery 插件,方便自己的使用。
复制代码 代码如下:

(function($){
$.extend({
documentMask: function(options){
// 扩展参数
var op = $.extend({
opacity: 0.8,
z: 10000,
bgcolor: '#000'
}, options);
// 创建一个 Mask 层,追加到 document.body
$('<div class="jquery_addmask"> </div>').appendTo(document.body).css({
position: 'absolute',
top: '0px',
left: '0px',
'z-index': op.z,
width: $(document).width(),
height: $(document).height(),
'background-color': op.bgcolor,
opacity: 0
}).fadeIn('slow', function(){
// 淡入淡出效果
$(this).fadeTo('slow', op.opacity);
}).click(function(){
// 单击事件,Mask 被销毁
$(this).fadeTo('slow', 0, function(){
$(this).remove();
});
});
return this;
}
});
})(jQuery);

使用方法
复制代码 代码如下:

$.documentMask();
$.documentMask({
'opacity': 0.6,
'bgcolor': '#E79673',
'z': 1000000
});

参数中,z 表示 z-index。
兼容性
支持 IE 6.0+, FF2+, Safari 3.1+, Opera 9.0+