1 ;(
2 function($) {
3 var DragPanelId = "divContext";
4 var _idiffx = 0;
5 var _idiffy = 0;
6 var _Div = null;
7 $.extend({
8
9 AttachDrag: function(dragId) {
10 if (dragId)
11 $._Div = document.getElementById(dragId);
12 else
13 $._Div = document.getElementById($.DragPanelId);
14 document.body.onmousedown = $._handleMouseDown;
15
16 },
17 _handleMouseDown: function() {
18 var oEvent = window.event;
19 if ($._Div) {
20 $._idiffx = oEvent.clientX - $._Div.offsetLeft;
21 $._idiffy = oEvent.clientY - $._Div.offsetTop;
22 document.body.onmousemove = $._handleMouseMove;
23 document.body.onmouseup = $._handleMouseUp;
24 }
25 },
26 _handleMouseMove: function() {
27 var oEvent = window.event;
28 $._Div.style.left = oEvent.clientX - $._idiffx;
29 $._Div.style.top = oEvent.clientY - $._idiffy;
30 $._Div.style.cursor = "move";
31 },
32 _handleMouseUp: function() {
33 document.body.onmousemove = null;
34 document.body.onmouseup = null;
35 $._Div.style.cursor = "default";
36 }
37 });
38 }
39 )(jQuery)
40
41 ;(
42 function($){
43
44 var divW;//div的高度
45 var divH;//div宽度
46 var clientH;//浏览器高度
47 var clientW//浏览器宽度
48 var divTitle;
49 var pageUrl;
50 var div_X;
51 var div_Y;
52
53 $.extend({
54 //清除背景锁定
55 clearLockScreen: function() {
56 $("#divLock").remove();
57 },
58
59 //清除DIV窗口
60 clearDivWindow: function() {
61 $("#divWindow").remove();
62 },
63 lockScreen:function(){
64 if($("#divLock").length==0){
65 clientH = $(window).height(); //浏览器高度
66 clientW = $(window).width(); //浏览器宽度
67 $("body").append("<div id='divLock'></div>") //增加DIV
68 $("#divLock").height(clientH);
69 $("#divLock").width(clientW);
70 $("#divLock").css("display", "block");
71 $("#divLock").css("background-color", "#000000");
72 $("#divLock").css("position", "fixed");
73 $("#divLock").css("z-index", "100");
74 $("#divLock").css("top", "0px");
75 $("#divLock").css("left", "0px");
76 $("#divLock").css("opacity", "0.5");
77 }
78 else
79 {
80 clientH =$(window).height();
81 clientW=$(window).width();
82 $("#divLock").height(clientH);
83 $("#divLock").width(clientW);
84
85 }
86 }
87 ,
88 divOpen:function(){
89 var minTop = 80; //弹出的DIV记顶部的最小距离
90 if ($("#divWindow").length == 0) {
91 clientH = $(window).height(); //浏览器高度
92 clientW = $(window).width(); //浏览器宽度
93 div_X = (clientW - divW) / 2; //DIV横坐标
94 div_Y = (clientH - divH) / 2; //DIV纵坐标
95 div_X += window.document.documentElement.scrollLeft; //DIV显示的实际横坐标
96 div_Y += window.document.documentElement.scrollTop; //DIV显示的实际纵坐标
97 if (div_Y < minTop) {
98 div_Y = minTop;
99 }
100 $("body").append("<div id='divWindow'><div id='divTitle'><img src='images/Close-1.gif' id='x' /></div><div id='divContent'>载入中...</div></div>"); //增加DIV
101 //divWindow的样式
102 $("#divWindow").css("position", "absolute");
103 $("#divWindow").css("z-index", "200");
104 $("#divWindow").css("left", (div_X + "px")); //定位DIV的横坐标
105 $("#divWindow").css("top", (div_Y + "px")); //定位DIV的纵坐标
106 $("#divWindow").css("opacity", "0.9");
107 $("#divWindow").width(divW);
108 $("#divWindow").height(divH);
109 $("#divWindow").css("background-color", "#FFFFFF");
110 $("#divWindow").css("border", "solid 1px #333333");
111 //divTitle的样式
112 $("#divTitle").css("height", "20px");
113 $("#divTitle").css("line-height", "20px");
114 $("#divTitle").css("background-color", "#333333");
115 $("#divTitle").css("padding", "3px 5px 1px 5px");
116 $("#divTitle").css("color", "#FFFFFF");
117 $("#divTitle").css("font-weight", "bold");
118 //x的样式
119 $("#x").css("float", "right");
120 $("#x").css("cursor", "pointer");
121 //divContent的样式
122 $("#divContent").css("padding", "10px");
123 }
124 else {
125 clientH = $(window).height(); //浏览器高度
126 clientW = $(window).width(); //浏览器宽度
127 div_X = (clientW - divW) / 2; //DIV横坐标
128 div_Y = (clientH - divH) / 2; //DIV纵坐标
129 div_X += window.document.documentElement.scrollLeft; //DIV显示的实际横坐标
130 div_Y += window.document.documentElement.scrollTop; //DIV显示的实际纵坐标
131 if (div_Y < minTop) {
132 div_Y = minTop;
133 }
134 $("#divWindow").css("left", (div_X + "px")); //定位DIV的横坐标
135 $("#divWindow").css("top", (div_Y + "px")); //定位DIV的纵坐标
136 }
137 }
138 ,
139 alterBgColor:function(){
140
141
142 $("tbody>tr").hover(
143 function(){
144 $(this).css("background-color","#E8E8E8");
145 },
146 function(){
147 $(this).css("background-color","white");
148
149 }
150 )
151
152 },
153 ShowForm:function(divWidth,divHeight,title,url,json){
154 divW= divWidth;
155 divH= divHeight;
156 divTitle = title;
157 pageUrl = url;
158 $.lockScreen();
159 $.divOpen();
160 $("#divTitle").append(divTitle);
161 $("#divContent").load(pageUrl,json,function(){
162 $.AttachDrag("divWindow");
163 $.alterBgColor();
164 });
165
166 $("#x").hover(
167
168 function() {
169 $(this).attr("src", "images/Close-2.gif");
170 },
171 function() {
172 $(this).attr("src", "images/Close-1.gif");
173 }
174 );
175 $("#x").click(
176 function() {
177 $.clearDivWindow();
178 $.clearLockScreen();
179 });
180 $(window).resize(
181 function() {
182 if ($("#divLock").length != 0) {
183 $.lockScreen();
184 }
185 if ($("#divWindow").length != 0) {
186 $.divOpen();
187 }
188 }
189 );
190
191 }
192
193 });
194 }
195 )(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">
<head>
<title></title>
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
<script src="Scripts/ShowForm.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$("#show").click(function () {
$.ShowForm(500, 320, '封装全局函数的插件Demo', 'ShowItem.aspx', {name:"zhangshan"});
})
})
</script>
</head>
<body>
<input type="button" value="点击演示" id="show"/>
</body>
</html>