找回密码
 注-册

QQ登录

只需一步,快速开始

查看: 1315|回复: 0

[特效] 用层模拟可移动的小窗口

[复制链接]
Leya 发表于 2008-3-31 11:24:13 | 显示全部楼层 |阅读模式
  1. <html>
  2. <head>
  3. <title>_xWin</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  5. <META NAME="Description" CONTENT="http://www.bakbuy.com">
  6. <style type='text/css'>
  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. //-->
  192. </script>

  193. <script language='JScript'>
  194. <!--
  195. function initialize()
  196. {
  197. var a = new xWin("1",160,200,200,200,"窗口1","xWin
  198. A Cool Pop Div Window
  199. Version:1.0
  200. 2002-8-13");
  201. var b = new xWin("2",240,200,100,100,"窗口2","Welcome to visited my personal website:
  202. <a href=http://www.bakbuy.com target=_blank>http://www.bakbuy.com</a>
  203. anducanalsosignmyguestbookat:
  204. <ahref=http://www ... bakbuy.com</a>

  205. thx!!!=)...");
  206. var c = new xWin("3",200,160,250,50,"窗口3","Copyright by <a href='mailto:webmaster@bakbuy.com'>Wildwind</a>!");
  207. ShowHide("1","none");//隐藏窗口1
  208. }
  209. window.onload = initialize;
  210. //-->
  211. </script>
  212. </head>
  213. <base target="_blank">
  214. <body onselectstart='return false' oncontextmenu='return false' >
  215. <a onclick="ShowHide('1',null);return false;" href="">窗口1</a>
  216. <a onclick="ShowHide('2',null);return false;" href="">窗口2</a>
  217. <a onclick="ShowHide('3',null);return false;" href="">窗口3</a>
  218. </body>
  219. </html>
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注-册

本版积分规则

Archiver|手机版|小黑屋|DoDVip ( 桂ICP备14000730号 )

GMT+8, 2025-5-1 18:20 , Processed in 0.119637 second(s), 20 queries .

Powered by Discuz! X3.5

Copyright © 2001-2024 Tencent Cloud.

快速回复 返回顶部 返回列表