一个jquery的弹出层的插件第1/2页

网络编程 JavaScript javascript类库 jquery 分类:[default] 更新日期: 2016-02-05
刚刚写的一个jquery的弹出层的插件
代码如下:

String.prototype.replaceAll = function(s1,s2){
return this.replace(new RegExp(s1,"gm"),s2);
};
(function($){
/*
* $-layer 0.1 - jquery pulg-in
*
* Copyright (c) 2008 King Wong
* $Date: 2008-09-28 $
*/
var ___win___ = window.self;
var ___self___ = window.self;
var ___id___ = "";
var ___settings___ = {};
var isMouseDown = false;
var currentElement = null;
var dropCallbacks = {};
var dragCallbacks = {};
var bubblings = {};
var lastMouseX;
var lastMouseY;
var lastElemTop;
var lastElemLeft;
var dragStatus = {};
var holdingHandler = false;
$.getMousePosition = function(e){
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
}
return { 'x': posx, 'y': posy };
};
$.updatePosition = function(e) {
var pos = $.getMousePosition(e);
var spanX = (pos.x - lastMouseX);
var spanY = (pos.y - lastMouseY);
var _top = (lastElemTop + spanY) > 0 ? (lastElemTop + spanY) : 0;
var _left = (lastElemLeft + spanX) > 0 ? (lastElemLeft + spanX) : 0;
$("#"+___id___,___win___.document).css("top", _top);
$("#"+___id___,___win___.document).css("left", _left);
};
$.fn.ondrag = function(callback){
return this.each(function(){
dragCallbacks[this.id] = callback;
});
};
$.fn.ondrop = function(callback){
return this.each(function(){
dropCallbacks[this.id] = callback;
});
};
$.fn.dragOff = function(){
return this.each(function(){
dragStatus[this.id] = 'off';
});
};
$.fn.dragOn = function(){
return this.each(function(){
dragStatus[this.id] = 'on';
});
};
$.extend({
layerSettings:{
id:"layerdiv",
target:window.self,
width:220,
height:220,
templete:'<div style="height:20px; width:@[email protected]; background-color:#777777;"><span style="position:relative; left:0px; top:0px; height:20px; width:100px;"><span >@[email protected]</span></span><span class="layerclose" style="position:relative; top:0px; float:right; right:20px; color:red;">close</span></div><div style="border:solid #ff0000 1px; width:@[email protected]; height:@[email protected];"><div style="width:100%; height:100%; background-color:#ffffff;" ></div></div>',
cssurl:'',
content:'',
title:'',
isbg:true,
opacity:0.3
},
layerSetup: function( settings ) {
$.extend( $.layerSettings, settings );
___settings___[settings.id] = settings;
___id___ = settings.id;
},
layershow:function(){
___win___ = $.layerSettings.target == undefined || $.layerSettings.target == null ? window.self : $.layerSettings.target;
var win = $.layerSettings.target == undefined || $.layerSettings.target == null ? window.self : $.layerSettings.target;
var __bw = $("body",win.document).width();
var __bh = $("body",win.document).height() > $(window).height() ? $("body",win.document).height() : $(window).height();
var _width = $.layerSettings.width;
var _height = $.layerSettings.height;
if(___win___.document.getElementById(___id___)) return;
var _moveid = ___id___ + "_move";
var _titleid = ___id___ + "_title";
var _contentid = ___id___ + "_content";
var _cssurl = $.layerSettings.cssurl;
var opacity = $.layerSettings.opacity;
(function(){
$("head",win.document).append('<link type="text/css" href="'+_cssurl+'" />');
})();
__index = $.layermaxindex();
var __left = (__bw - _width) > 0 ? (__bw - _width)/2 : 0;
var __top = 100;
var __bgDiv = '<div style="background:#000000; filter:alpha(opacity='+(opacity*100)+'); opacity: '+opacity+'; width:'+__bw+'px; height:'+__bh+'px; z-index:'+(__index++)+'; position:absolute; left:0px; top:0px;"></div>';
if($.layerSettings.isbg)
{
$("body",win.document).append(__bgDiv);
}
$("body",win.document).append('<div style="z-index:'+__index+';position:absolute; left:'+__left+'px; top:'+__top+'px;"></div>');
var _templete = $.layerSettings.templete;
var __templete = _templete.replaceAll("@[email protected]",_width).replaceAll("@[email protected]",_height).replaceAll("@[email protected]",_titleid).replaceAll("@[email protected]",_contentid).replaceAll("@[email protected]",jQuery.layerSettings.title).replaceAll("@[email protected]",_moveid);
$("#"+___id___,win.document).append(__templete);
$("#"+_contentid,win.document).append($.layerSettings.content);
var self = window.self;
var ___win = $.layerSettings.target.document;
var idd = ___id___;
$(".layerclose",win.document).bind("click",function()
{
self.$.layerclose(idd,___win);
});
$("#"+___id___,win.document).bind("click",function()
{
var id = this.id;
self.$.layerSetup(___settings___[id]);
self.$(this).css("z-index",$.layermaxindex());
});
$(win.document,win).bind("click",function(e)
{
var pos = self.$.getMousePosition(e);
});
$(win.document,win).mousemove(function(e){
if(isMouseDown && dragStatus[currentElement.id] != 'false'){
self.$.updatePosition(e);
if(dragCallbacks[currentElement.id] != undefined){
dragCallbacks[currentElement.id](e, currentElement);
}
return false;
}
});
$(win.document,win).mouseup(function(e){
if(isMouseDown && dragStatus[currentElement.id] != 'false'){
isMouseDown = false;
if(dropCallbacks[currentElement.id] != undefined){
dropCallbacks[currentElement.id](e, currentElement);
}
return false;
}
});
(function(){
bubblings[___id___] = true;
dragStatus[___id___] = "on";
//setHandler
bubblings[this.id] = true;
dragStatus[_moveid] = "handler";
$("#"+_moveid,win.document).css("cursor", "move");
$("#"+_moveid,win.document).mousedown(function(e){
var id = this.id.replace("_move","");
___id___ = id;
self.$("#"+id,win.document).css("z-index",$.layermaxindex());
self.$.layerSetup(___settings___[id]);
if((dragStatus[___id___] == "off") || (dragStatus[___id___] == "handler" && !holdingHandler))
return bubblings["#"+___id___];
isMouseDown = true;
currentElement = self.$("#"+___id___);
var pos = self.$.getMousePosition(e);
lastMouseX = pos.x;
lastMouseY = pos.y;
lastElemTop = win.document.getElementById(___id___).offsetTop;
lastElemLeft = win.document.getElementById(___id___).offsetLeft;
self.$.updatePosition(e);
holdingHandler = true;
});
$("#"+_moveid,win.document).mouseup(function(e){
holdingHandler = false;
});
//end setHandler
})();
},
layerclose:function(__id,__win)
{
$("#"+__id+"_background",__win).remove();
$("#"+__id,__win).remove();
},
layermaxindex:function()
{
var ___index = 0;
$.each($("*",___win___.document),function(i,n){
var __tem = $(n).css("z-index");
if(__tem>0)
{
if(__tem > ___index)
{
___index = __tem + 1;
}
}
});
return ___index;
}
});
})(jQuery);

使用方法:

> 本站内容系网友提交或本网编辑转载,其目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权和其它问题,请及时与本网联系,我们将在第一时间删除内容!

相关文章
  • ie9下关闭弹出窗口出现__flash__removeCallback未定义错误
    在关闭弹出窗口时,出现__flash__removeCallback未定义错误.而且是关了又出现,关于这个问题的解决方法如下使用swfupload作为上传组件,artdialog作为弹出窗口,在关闭弹出窗口时,出现"__flash__removeCallback"未定义错误.而且是关了又出现.网上有些解决方案,主要就是说覆写"_ ...
  • Jquery和BigFileUpload实现大文件上传及进度条显示
    Jquery和BigFileUpload实现大文件上传及进度条显示
    这篇文章主要介绍了Jquery和BigFileUpload实现大文件上传及进度条显示的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下实现方法:用到了高山来客 的bigfileupload组件,用高山来客的方法,弹出一个模式窗口,然后不停刷新获取进度,始终觉得体验感不好,于是想到用jquery来实现无刷新进度显示,因为提交页面后, 不能让其刷新页面 ...
  • ASP.NETWebApi2实现多文件打包并下载文件的实例
    ASP.NETWebApi2实现多文件打包并下载文件的实例
    这篇文章主要介绍了ASP.NET Web Api 2利用ByteArrayContent和StreamContent实现多文件打包并下载的方法,提供源码下载,需要的朋友可以参考下.最近由于工作和个人事务,站点也好久没更新了,但这并不影响我对.NET的热情.站点的更新工作还是得想办法抽时间来完成的. 今天利用中午的时间来写一篇关于Asp.Net Web Api ...
  • ASP.NET(C#)WebApi通过文件流下载文件的实例
    这篇文章主要介绍了ASP.NETC# Web Api通过文件流下载文件的方法,提供源码下载,需要的朋友可以参考下.下载文件到本地是很多项目开发中需要实现的一个很简单的功能.说简单,是从具体的代码实现上来说的,.NET的文件下载方式有很多种,本示例给大家介绍的是ASP.NET Web Api方式返回HttpResponseMessage下载文件到本地.实现的方 ...
  • 探讨Ajax中有关readyState状态值和status状态码)的问题
    这篇文章主要介绍了探讨Ajax中有关readyState状态值和status状态码的问题的相关资料,非常不错,具有参考借鉴价值,需要的朋友可以参考下先看下面一段代码,然后给大家详细介绍,Ajax中有关readyState(状态值)和status(状态码)的问题,具体内容如下所示: var getXmlHttpRequest = function () { t ...
  • 利用ASP.NETMVC+Bootstrap搭建个人博客之praise.js点赞特效插件(二)
    这篇文章主要介绍了利用ASP.NET和MVC+Bootstrap搭建个人博客之praise.js点赞特效插件二的相关资料,需要的朋友可以参考下在上篇文章给大家介绍了利用ASP.NET MVC和Bootstrap快速搭建响应式个人博客站(一).接下来给大家介绍如果做个点赞插件,一起通过本文学习吧! 1. 为啥要做这个点赞插件?    praise.js是一款小 ...
猜你喜欢