一个jquery的弹出层的插件第1/2页_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:@width@px; background-color:#777777;"><span id="@moveid@" style="position:relative; left:0px; top:0px; height:20px; width:100px;"><span id="@titleid@">@title@</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:@width@px; height:@height@px;"><div style="width:100%; height:100%; background-color:#ffffff;" id="@contentid@"></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+'" rel="stylesheet" />');
})();
__index = $.layermaxindex();
var __left = (__bw - _width) > 0 ? (__bw - _width)/2 : 0;
var __top = 100;
var __bgDiv = '<div id="'+___id___+'_background" 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 id="'+___id___+'" style="z-index:'+__index+';position:absolute; left:'+__left+'px; top:'+__top+'px;"></div>');
var _templete = $.layerSettings.templete;
var __templete = _templete.replaceAll("@width@",_width).replaceAll("@height@",_height).replaceAll("@titleid@",_titleid).replaceAll("@contentid@",_contentid).replaceAll("@title@",jQuery.layerSettings.title).replaceAll("@moveid@",_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);

使用方法:

当前1/2页 12下一页阅读全文

时间: 2024-10-26 05:50:35

一个jquery的弹出层的插件第1/2页_jquery的相关文章

jQuery Dialog 弹出层对话框插件_jquery

原理很简单,通过JS动态构建一个div层,将其插入到body中,然后通过调整position的CSS属性为absolute或fixed,使其脱离原来的文档流的位置.再通过适当的加工美化就成了. 复制代码 代码如下: <!-- 背景遮盖层 --> <div class="dialog-overlay"></div> <!-- 对话框 --> <div class="dialog"> <div class

帮忙弄一个jquery的弹出层,新手不会使用呢

问题描述 这里是HTML代码<!--查看图片--><divid="PictureDetail"runat="server"><div><asp:ButtonID="closeButton"runat="server"Text="关闭"/>    <asp:ButtonID="setCover"runat="server&qu

jQuery 弹出层对话框插件实例

<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3c.org/tr/1999/rec-html401-19991224/loose.dtd"> <html><head lang=zh><title>jquery dialog弹出层对话框插件演示</title> <meta http-equiv=co

JQuery.Boxy 弹出层的实例

 代码如下 复制代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head>     <title></t

jquery实现仿新浪微博带动画效果弹出层代码(可关闭、可拖动)_jquery

本文实例讲述了jquery实现仿新浪微博带动画效果弹出层代码.分享给大家供大家参考.具体如下: 这是一款jquery实现带动画的弹出层,最开始是模拟新浪微博中的弹出层,后来引入了jQuery,又想了想,加入点动画效果不知怎么样,后来就写出了这么一个弹出的网页层效果,你点击按钮后就可以看到一个渐出的可关闭的弹出层,点击关闭后,当然也是渐渐的消失的,移动时根据鼠标位置计算控件左上角的绝对位置,松开鼠标后停止移动并恢复成不透明. 运行效果截图如下: 在线演示地址如下: http://demo.jb51

jquery dialog 弹出层内容错误

问题描述 jquery dialog 弹出层内容错误 弹出框时不时的弹出父页面的内容,经过测试与页面表格样式无关,忘有大神帮忙解决一下. 解决方案 jQuery弹出层插件DialogJquery UI dialog弹出层插件jquery dialog-优雅的弹出框 解决方案二: <!DOCTYPE html><html xmlns=""http://www.w3.org/1999/xhtml""><head> <meta h

jquery pop弹出层下拉效果实现

jquery pop弹出层下拉效果实现 注:本文章末提供jquery文件,自己下载一个就可以了. <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

jquery实现弹出层效果实例

  本文实例讲述了jquery实现弹出层效果的方法.分享给大家供大家参考.具体实现方法如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70

jquery实现弹出层遮罩效果的简单实例

 这篇文章主要介绍了jquery实现弹出层遮罩效果的简单实例.需要的朋友可以过来参考下,希望对大家有所帮助 代码如下: <input type="button" value="高级搜索" id="click_test4" />"; var content4 = "<center>高级搜索</center><form action='' method='post' id='formUse