[JavaScript] 可拖动层js代码 →→→→→进入此内容的聊天室

来自 , 2019-04-14, 写在 JavaScript, 查看 150 次.
URL http://www.code666.cn/view/7ee6f2b3
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>DOM_text01</title>
  6. <style type="text/css">
  7. body,span,div,td{font-size:12px;line-height:1.5em;color:#849BCA;}
  8. #bodyL{
  9. float:left;
  10. width:84px;
  11. margin-right:2px;
  12. }
  13. a.od{
  14. width:80px;
  15. height:25px;
  16. line-height:25px;
  17. text-align:center;
  18. font-weight:bold;
  19. border: 2px solid #849BCA;
  20. display:block;
  21. color:#547BC9;
  22. float:left;
  23. text-decoration:none;
  24. margin-top:2px;
  25. }
  26. a.od:link{
  27. background:#EEF1F8;
  28. }
  29. a.od:visited{
  30. background:#EEF1F8;
  31. }
  32. a.od:hover{
  33. background:#EEE;
  34. }
  35. a.od:active{
  36. background:#EEE;
  37. }
  38. #fd{
  39. width:500px;
  40. height:200px;
  41. background:#EDF1F8;
  42. border: 2px solid #849BCA;
  43. margin-top:2px;
  44. margin-left:2px;
  45. float:left;
  46. overflow:hidden;
  47. position:absolute;
  48. left:0px;
  49. top:0px;
  50. cursor:move;
  51. float:left;
  52. /*filter:alpha(opacity=50);*/
  53.  
  54. }
  55. .content{
  56. padding:10px;
  57. }
  58. </style>
  59. </head>
  60. <body>
  61. <div id="bodyL">
  62. <a href="#" class="od" onclick = "show('fd');return false;">
  63. [打开层]
  64. </a>
  65. <a href="#" class="od" onclick = "closeed('fd');return false;">
  66. [关闭层]
  67. </a>
  68. </div>
  69. <div id="fd" style="display:none;filter:alpha(opacity=100);opacity:1;">
  70. <div class="content">移动层</div>
  71. </div>
  72.  
  73. <script type="text/javascript">
  74. var prox;
  75. var proy;
  76. var proxc;
  77. var proyc;
  78. function show(id){/*--打开--*/
  79. clearInterval(prox);
  80. clearInterval(proy);
  81. clearInterval(proxc);
  82. clearInterval(proyc);
  83. var o = document.getElementById(id);
  84. o.style.display = "block";
  85. o.style.width = "1px";
  86. o.style.height = "1px";
  87. prox = setInterval(function(){openx(o,500)},10);
  88. }
  89. function openx(o,x){/*--打开x--*/
  90. var cx = parseInt(o.style.width);
  91. if(cx < x)
  92. {
  93. o.style.width = (cx + Math.ceil((x-cx)/5)) +"px";
  94. }
  95. else
  96. {
  97. clearInterval(prox);
  98. proy = setInterval(function(){openy(o,200)},10);
  99. }
  100. }
  101. function openy(o,y){/*--打开y--*/
  102. var cy = parseInt(o.style.height);
  103. if(cy < y)
  104. {
  105. o.style.height = (cy + Math.ceil((y-cy)/5)) +"px";
  106. }
  107. else
  108. {
  109. clearInterval(proy);
  110. }
  111. }
  112. function closeed(id){/*--关闭--*/
  113. clearInterval(prox);
  114. clearInterval(proy);
  115. clearInterval(proxc);
  116. clearInterval(proyc);
  117. var o = document.getElementById(id);
  118. if(o.style.display == "block")
  119. {
  120. proyc = setInterval(function(){closey(o)},10);
  121. }
  122. }
  123. function closey(o){/*--打开y--*/
  124. var cy = parseInt(o.style.height);
  125. if(cy > 0)
  126. {
  127. o.style.height = (cy - Math.ceil(cy/5)) +"px";
  128. }
  129. else
  130. {
  131. clearInterval(proyc);
  132. proxc = setInterval(function(){closex(o)},10);
  133. }
  134. }
  135. function closex(o){/*--打开x--*/
  136. var cx = parseInt(o.style.width);
  137. if(cx > 0)
  138. {
  139. o.style.width = (cx - Math.ceil(cx/5)) +"px";
  140. }
  141. else
  142. {
  143. clearInterval(proxc);
  144. o.style.display = "none";
  145. }
  146. }
  147.  
  148. /*-------------------------鼠标拖动---------------------*/
  149. var od = document.getElementById("fd");
  150. var dx,dy,mx,my,mouseD;
  151. var odrag;
  152. var isIE = document.all ? true : false;
  153. document.onmousedown = function(e){
  154. var e = e ? e : event;
  155. if(e.button == (document.all ? 1 : 0))
  156. {
  157. mouseD = true;
  158. }
  159. }
  160. document.onmouseup = function(){
  161. mouseD = false;
  162. odrag = "";
  163. if(isIE)
  164. {
  165. od.releaseCapture();
  166. od.filters.alpha.opacity = 100;
  167. }
  168. else
  169. {
  170. window.releaseEvents(od.MOUSEMOVE);
  171. od.style.opacity = 1;
  172. }
  173. }
  174.  
  175. //function readyMove(e){
  176. od.onmousedown = function(e){
  177. odrag = this;
  178. var e = e ? e : event;
  179. if(e.button == (document.all ? 1 : 0))
  180. {
  181. mx = e.clientX;
  182. my = e.clientY;
  183. od.style.left = od.offsetLeft + "px";
  184. od.style.top = od.offsetTop + "px";
  185. if(isIE)
  186. {
  187. od.setCapture();
  188. od.filters.alpha.opacity = 50;
  189. }
  190. else
  191. {
  192. window.captureEvents(Event.MOUSEMOVE);
  193. od.style.opacity = 0.5;
  194. }
  195.  
  196. //alert(mx);
  197. //alert(my);
  198.  
  199. }
  200. }
  201. document.onmousemove = function(e){
  202. var e = e ? e : event;
  203.  
  204. //alert(mrx);
  205. //alert(e.button);
  206. if(mouseD==true && odrag)
  207. {
  208. var mrx = e.clientX - mx;
  209. var mry = e.clientY - my;
  210. od.style.left = parseInt(od.style.left) +mrx + "px";
  211. od.style.top = parseInt(od.style.top) + mry + "px";
  212. mx = e.clientX;
  213. my = e.clientY;
  214.  
  215. }
  216. }
  217.  
  218. </script>
  219. </body>
  220. </html>
  221.  
  222. //javascript/1072

回复 "可拖动层js代码"

这儿你可以回复上面这条便签

captcha