用層模擬的小窗口(可拖動展合)
1
<html>
2
<head>
3
<title>網頁特效---用層模擬的小窗口(可拖動展合)</title>
4
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
5
6
<style type='text/<a href="http://www.iwangye.com/c23.aspx" title="">
css</a>'>
7
<!--
8
body{
}{font-size:12px;}
9
a:visited{
}{text-decoration:none;color:slategray;}
10
a:hover{
}{text-decoration:underline;color:slategray;}
11
a:link{
}{text-decoration:none;color:slategray;}
12
-->
13
</style>
14
<script language=JScript>
15
<!--
16
//可以打包為js文件;
17
var x0=0,y0=0,x1=0,y1=0;
18
var offx=6,offy=6;
19
var moveable=false;
20
var hover='orange',normal='#336699';//color;
21
var index=10000;//z-index;
22
//開始拖動;
23
function startDrag(obj)
24

{
25
if(event.button==1)
26
{
27
//鎖定標題欄;
28
obj.setCapture();
29
//定義對象;
30
var win = obj.parentNode;
31
var sha = win.nextSibling;
32
//記錄鼠標和層位置;
33
x0 = event.clientX;
34
y0 = event.clientY;
35
x1 = parseInt(win.style.left);
36
y1 = parseInt(win.style.top);
37
//記錄顏色;
38
normal = obj.style.backgroundColor;
39
//改變風格;
40
obj.style.backgroundColor = hover;
41
win.style.borderColor = hover;
42
obj.nextSibling.style.color = hover;
43
sha.style.left = x1 + offx;
44
sha.style.top = y1 + offy;
45
moveable = true;
46
}
47
}
48
//拖動;
49
function drag(obj)
50

{
51
if(moveable)
52
{
53
var win = obj.parentNode;
54
var sha = win.nextSibling;
55
win.style.left = x1 + event.clientX - x0;
56
win.style.top = y1 + event.clientY - y0;
57
sha.style.left = parseInt(win.style.left) + offx;
58
sha.style.top = parseInt(win.style.top) + offy;
59
}
60
}
61
//停止拖動;
62
function stopDrag(obj)
63

{
64
if(moveable)
65
{
66
var win = obj.parentNode;
67
var sha = win.nextSibling;
68
var msg = obj.nextSibling;
69
win.style.borderColor = normal;
70
obj.style.backgroundColor = normal;
71
msg.style.color = normal;
72
sha.style.left = obj.parentNode.style.left;
73
sha.style.top = obj.parentNode.style.top;
74
obj.releaseCapture();
75
moveable = false;
76
}
77
}
78
//獲得焦點;
79
function getFocus(obj)
80

{
81
if(obj.style.zIndex!=index)
82
{
83
index = index + 2;
84
var idx = index;
85
obj.style.zIndex=idx;
86
obj.nextSibling.style.zIndex=idx-1;
87
}
88
}
89
//最小化;
90
function min(obj)
91

{
92
var win = obj.parentNode.parentNode;
93
var sha = win.nextSibling;
94
var tit = obj.parentNode;
95
var msg = tit.nextSibling;
96
var flg = msg.style.display=="none";
97
if(flg)
98
{
99
win.style.height = parseInt(msg.style.height) + parseInt(tit.style.height) + 2*2;
100
sha.style.height = win.style.height;
101
msg.style.display = "block";
102
obj.innerHTML = "0";
103
}
104
else
105
{
106
win.style.height = parseInt(tit.style.height) + 2*2;
107
sha.style.height = win.style.height;
108
obj.innerHTML = "2";
109
msg.style.display = "none";
110
}
111
}
112
//創建一個對象;
113
function xWin(id,w,h,l,t,tit,msg)
114

{
115
index = index+2;
116
this.id = id;
117
this.width = w;
118
this.height = h;
119
this.left = l;
120
this.top = t;
121
this.zIndex = index;
122
this.title = tit;
123
this.message = msg;
124
this.obj = null;
125
this.bulid = bulid;
126
this.bulid();
127
}
128
//初始化;
129
function bulid()
130

{
131
var str = ""
132
+ "<div id=xMsg" + this.id + " "
133
+ "style='"
134
+ "z-index:" + this.zIndex + ";"
135
+ "width:" + this.width + ";"
136
+ "height:" + this.height + ";"
137
+ "left:" + this.left + ";"
138
+ "top:" + this.top + ";"
139
+ "background-color:" + normal + ";"
140
+ "color:" + normal + ";"
141
+ "font-size:8pt;"
142
+ "font-family:Tahoma;"
143
+ "position:absolute;"
144
+ "cursor:default;"
145
+ "border:2px solid " + normal + ";"
146
+ "' "
147
+ "onmousedown='getFocus(this)'>"
148
+ "<div "
149
+ "style='"
150
+ "background-color:" + normal + ";"
151
+ "width:" + (this.width-2*2) + ";"
152
+ "height:20;"
153
+ "color:white;"
154
+ "' "
155
+ "onmousedown='startDrag(this)' "
156
+ "onmouseup='stopDrag(this)' "
157
+ "onmousemove='drag(this)' "
158
+ "ondblclick='min(this.childNodes[1])'"
159
+ ">"
160
+ "<span style='width:" + (this.width-2*12-4) + ";padding-left:3px;'>" + this.title + "</span>"
161
+ "<span style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='min(this)'>0</span>"
162
+ "<span style='width:12;border-width:0px;color:white;font-family:webdings;' onclick='ShowHide(\""+this.id+"\",null)'>r</span>"
163
+ "</div>"
164
+ "<div style='"
165
+ "width:100%;"
166
+ "height:" + (this.height-20-4) + ";"
167
+ "background-color:white;"
168
+ "line-height:14px;"
169
+ "word-break:break-all;"
170
+ "padding:3px;"
171
+ "'>" + this.message + "</div>"
172
+ "</div>"
173
+ "<div id=xMsg" + this.id + "bg style='"
174
+ "width:" + this.width + ";"
175
+ "height:" + this.height + ";"
176
+ "top:" + this.top + ";"
177
+ "left:" + this.left + ";"
178
+ "z-index:" + (this.zIndex-1) + ";"
179
+ "position:absolute;"
180
+ "background-color:black;"
181
+ "filter:alpha(opacity=40);"
182
+ "'></div>";
183
document.body.insertAdjacentHTML("beforeEnd",str);
184
}
185
//顯示隱藏窗口
186
function ShowHide(id,dis)
{
187
var bdisplay = (dis==null)?((document.getElementById("xMsg"+id).style.display=="")?"none":""):dis
188
document.getElementById("xMsg"+id).style.display = bdisplay;
189
document.getElementById("xMsg"+id+"bg").style.display = bdisplay;
190
}
191
//modify by haiwa @ 2005-7-14
192
//
193
//-->
194
</script>
195
196
<script language='JScript'>
197
<!--
198
function initialize()
199

{
200
var a = new xWin("1",160,200,200,200,"窗口1","xWin <br> A Cool Pop Div Window<br>Version:1.0<br>2002-8-13");
201
var b = new xWin("2",240,200,100,100,"窗口2","Welcome to visited my personal website:<br><a href=http://linkweb.cn/js target=_blank>http://linkweb.cn/js</a><br>and u can also sign my guestbook at:<br><a href=http://linkweb.cn/Js/GBook/Index.php target=_blank>http://linkweb.cn/Js/GBook/Index.php</a><br><br>
");
202
var c = new xWin("3",200,160,250,50,"窗口3","Copyright by <a href='mailto:mailluwei@163.com'>LinkWeb.cN</a>!");
203
ShowHide("1","none");//隱藏窗口1
204
}
205
window.onload = initialize;
206
//-->
207
</script>
208
</head>
209
<base target="_blank">
210
<body onselectstart='return false' oncontextmenu='return false' >
211
<a onclick="ShowHide('1',null);return false;" href="">窗口1</a>
212
<a onclick="ShowHide('2',null);return false;" href="">窗口2</a>
213
<a onclick="ShowHide('3',null);return false;" href="">窗口3</a>
214
</body>
215
</html>
216
217

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

71

72

73

74

75

76

77

78

79

80



81

82



83

84

85

86

87

88

89

90

91



92

93

94

95

96

97

98



99

100

101

102

103

104

105



106

107

108

109

110

111

112

113

114



115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130



131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186



187

188

189

190

191

192

193

194

195

196



197

198

199



200

201


202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

posted on 2007-05-23 11:55 朱巖 閱讀(453) 評論(0) 編輯 收藏 所屬分類: JavaScript文章