TShopping

 找回密碼
 註冊
搜索
查看: 725|回復: 2

[教學] 帶陰影的可拖動的浮動層

[複製鏈接]
發表於 2008-9-23 20:23:53 | 顯示全部樓層 |閱讀模式
 
Push to Facebook Push to Plurk Push to Twitter 
先提供語法,有空再做演

  1. <html>
  2. <head>
  3. <title>MyPixbot</title>

  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <script language="JavaScript" type="text/JavaScript">
  6. <!--
  7. function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  8.   if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
  9.     document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  10.   else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
  11. }
  12. MM_reloadPage(true);
  13. function MM_findObj(n, d) { //v4.01
  14.   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
  15.     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  16.   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  17.   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  18.   if(!x && d.getElementById) x=d.getElementById(n); return x;
  19. }
  20. function MM_showHideLayers() { //v6.0
  21.   var i,p,v,obj,args=MM_showHideLayers.arguments;
  22.   for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
  23.     if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
  24.     obj.visibility=v; }
  25. }
  26. function MM_dragLayer(objName,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v4.01
  27.   //Copyright 1998 Macromedia, Inc. All rights reserved.
  28.   var i,j,aLayer,retVal,curDrag=null,curLeft,curTop,IE=document.all,NS4=document.layers;
  29.   var NS6=(!IE&&document.getElementById), NS=(NS4||NS6); if (!IE && !NS) return false;
  30.   retVal = true; if(IE && event) event.returnValue = true;
  31.   if (MM_dragLayer.arguments.length > 1) {
  32.     curDrag = MM_findObj(objName); if (!curDrag) return false;
  33.     if (!document.allLayers) { document.allLayers = new Array();
  34.       with (document) if (NS4) { for (i=0; i<layers.length; i++) allLayers[i]=layers[i];
  35.         for (i=0; i<allLayers.length; i++) if (allLayers[i].document && allLayers[i].document.layers)
  36.           with (allLayers[i].document) for (j=0; j<layers.length; j++) allLayers[allLayers.length]=layers[j];
  37.       } else {
  38.         if (NS6) { var spns = getElementsByTagName("span"); var all = getElementsByTagName("div");
  39.           for (i=0;i<spns.length;i++) if (spns[i].style&&spns[i].style.position) allLayers[allLayers.length]=spns[i];}
  40.         for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i];
  41.     } }
  42.     curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT;
  43.     curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT;
  44.     curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront;
  45.     curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS;
  46.     curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS;
  47.     curDrag.MM_oldZ = (NS4)?curDrag.zIndex:curDrag.style.zIndex;
  48.     curLeft= (NS4)?curDrag.left:(NS6)?parseInt(curDrag.style.left):curDrag.style.pixelLeft;
  49.     if (String(curLeft)=="NaN") curLeft=0; curDrag.MM_startL = curLeft;
  50.     curTop = (NS4)?curDrag.top:(NS6)?parseInt(curDrag.style.top):curDrag.style.pixelTop;
  51.     if (String(curTop)=="NaN") curTop=0; curDrag.MM_startT = curTop;
  52.     curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop-cU;
  53.     curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop+cD;
  54.     curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS!
  55.     document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer;
  56.     if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  57.   } else {
  58.     var theEvent = ((NS)?objName.type:event.type);
  59.     if (theEvent == 'mousedown') {
  60.       var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
  61.       var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
  62.       var maxDragZ=null; document.MM_maxZ = 0;
  63.       for (i=0; i<document.allLayers.length; i++) { aLayer = document.allLayers[i];
  64.         var aLayerZ = (NS4)?aLayer.zIndex:parseInt(aLayer.style.zIndex);
  65.         if (aLayerZ > document.MM_maxZ) document.MM_maxZ = aLayerZ;
  66.         var isVisible = (((NS4)?aLayer.visibility:aLayer.style.visibility).indexOf('hid') == -1);
  67.         if (aLayer.MM_dragOk != null && isVisible) with (aLayer) {
  68.           var parentL=0; var parentT=0;
  69.           if (NS6) { parentLayer = aLayer.parentNode;
  70.             while (parentLayer != null && parentLayer.style.position) {            
  71.               parentL += parseInt(parentLayer.offsetLeft); parentT += parseInt(parentLayer.offsetTop);
  72.               parentLayer = parentLayer.parentNode;
  73.           } } else if (IE) { parentLayer = aLayer.parentElement;      
  74.             while (parentLayer != null && parentLayer.style.position) {
  75.               parentL += parentLayer.offsetLeft; parentT += parentLayer.offsetTop;
  76.               parentLayer = parentLayer.parentElement; } }
  77.           var tmpX=mouseX-(((NS4)?pageX:((NS6)?parseInt(style.left):style.pixelLeft)+parentL)+MM_hLeft);
  78.           var tmpY=mouseY-(((NS4)?pageY:((NS6)?parseInt(style.top):style.pixelTop) +parentT)+MM_hTop);
  79.           if (String(tmpX)=="NaN") tmpX=0; if (String(tmpY)=="NaN") tmpY=0;
  80.           var tmpW = MM_hWidth;  if (tmpW <= 0) tmpW += ((NS4)?clip.width :offsetWidth);
  81.           var tmpH = MM_hHeight; if (tmpH <= 0) tmpH += ((NS4)?clip.height:offsetHeight);
  82.           if ((0 <= tmpX && tmpX < tmpW && 0 <= tmpY && tmpY < tmpH) && (maxDragZ == null
  83.               || maxDragZ <= aLayerZ)) { curDrag = aLayer; maxDragZ = aLayerZ; } } }
  84.       if (curDrag) {
  85.         document.onmousemove = MM_dragLayer; if (NS4) document.captureEvents(Event.MOUSEMOVE);
  86.         curLeft = (NS4)?curDrag.left:(NS6)?parseInt(curDrag.style.left):curDrag.style.pixelLeft;
  87.         curTop = (NS4)?curDrag.top:(NS6)?parseInt(curDrag.style.top):curDrag.style.pixelTop;
  88.         if (String(curLeft)=="NaN") curLeft=0; if (String(curTop)=="NaN") curTop=0;
  89.         MM_oldX = mouseX - curLeft; MM_oldY = mouseY - curTop;
  90.         document.MM_curDrag = curDrag;  curDrag.MM_SNAPPED=false;
  91.         if(curDrag.MM_toFront) {
  92.           eval('curDrag.'+((NS4)?'':'style.')+'zIndex=document.MM_maxZ+1');
  93.           if (!curDrag.MM_dropBack) document.MM_maxZ++; }
  94.         retVal = false; if(!NS4&&!NS6) event.returnValue = false;
  95.     } } else if (theEvent == 'mousemove') {
  96.       if (document.MM_curDrag) with (document.MM_curDrag) {
  97.         var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
  98.         var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
  99.         newLeft = mouseX-MM_oldX; newTop  = mouseY-MM_oldY;
  100.         if (MM_bL!=null) newLeft = Math.max(newLeft,MM_bL);
  101.         if (MM_bR!=null) newLeft = Math.min(newLeft,MM_bR);
  102.         if (MM_bT!=null) newTop  = Math.max(newTop ,MM_bT);
  103.         if (MM_bB!=null) newTop  = Math.min(newTop ,MM_bB);
  104.         MM_LEFTRIGHT = newLeft-MM_startL; MM_UPDOWN = newTop-MM_startT;
  105.         if (NS4) {left = newLeft; top = newTop;}
  106.         else if (NS6){style.left = newLeft; style.top = newTop;}
  107.         else {style.pixelLeft = newLeft; style.pixelTop = newTop;}
  108.         if (MM_dragJS) eval(MM_dragJS);
  109.         retVal = false; if(!NS) event.returnValue = false;
  110.     } } else if (theEvent == 'mouseup') {
  111.       document.onmousemove = null;
  112.       if (NS) document.releaseEvents(Event.MOUSEMOVE);
  113.       if (NS) document.captureEvents(Event.MOUSEDOWN); //for mac NS
  114.       if (document.MM_curDrag) with (document.MM_curDrag) {
  115.         if (typeof MM_targL =='number' && typeof MM_targT == 'number' &&
  116.             (Math.pow(MM_targL-((NS4)?left:(NS6)?parseInt(style.left):style.pixelLeft),2)+
  117.              Math.pow(MM_targT-((NS4)?top:(NS6)?parseInt(style.top):style.pixelTop),2))<=MM_tol) {
  118.           if (NS4) {left = MM_targL; top = MM_targT;}
  119.           else if (NS6) {style.left = MM_targL; style.top = MM_targT;}
  120.           else {style.pixelLeft = MM_targL; style.pixelTop = MM_targT;}
  121.           MM_SNAPPED = true; MM_LEFTRIGHT = MM_startL-MM_targL; MM_UPDOWN = MM_startT-MM_targT; }
  122.         if (MM_everyTime || MM_SNAPPED) eval(MM_dropJS);
  123.         if(MM_dropBack) {if (NS4) zIndex = MM_oldZ; else style.zIndex = MM_oldZ;}
  124.         retVal = false; if(!NS) event.returnValue = false; }
  125.       document.MM_curDrag = null;
  126.     }
  127.     if (NS) document.routeEvent(objName);
  128.   } return retVal;
  129. }
  130. function loadwin(obj){
  131. with(MM_findObj(obj))with(style){
  132.   filters[0].apply();
  133.   display='';
  134.   filters[0].play();
  135. }
  136. }
  137. function cs(captionBG,bodyBG,tableBG){
  138. oldBody=document.body;
  139. with(oldBody){
  140.   var newBody=cloneNode();
  141.   style.filter='blendtrans(duration=1)';
  142.   filters[0].apply();
  143.   with(document.styleSheets[0]){
  144.    with(rules[0].style){backgroundColor=captionBG;}
  145.    with(rules[1].style){backgroundColor=bodyBG;}
  146.    with(rules[2].style){backgroundColor=tableBG}
  147.   }
  148.   filters[0].play();
  149.   setTimeout(function(){
  150.     if(oldBody!=null){
  151.      oldBody.applyElement(newBody, "inside")
  152.      oldBody.swapNode(newBody);
  153.      oldBody.removeNode(true);
  154.      }
  155.     },1500);
  156. }
  157. }
  158. //-->
  159. </script>
  160. <style type="text/css">
  161. <!--
  162. .caption {
  163. font-size: 9px;
  164. color: #FFFFFF;
  165. background-color: #00CCFF;
  166. padding-left: 5px;
  167. cursor: default;
  168. font-family: "Verdana", "Arial";
  169. border: 1px inset;
  170. }
  171. body {
  172. background-color: #f6f6f6;
  173. border: 1px inset;
  174. overflow: hidden;
  175. }
  176. table {
  177. background-color: #eeeeee;
  178. }
  179. td {
  180. font-family: "Verdana", "Arial";
  181. font-size: 9px;
  182. border: 0px;
  183. }
  184. .win {
  185. filter:BlendTrans(duration=1) DropShadow(Color=#cccccc, OffX=3, OffY=3) alpha(opacity=90)
  186. }
  187. a {
  188. text-decoration: none;
  189. color: #003399;
  190. }
  191. a:hover {
  192. color: #FF0000;
  193. }
  194. input {
  195. font-family: "Verdana", "Arial";
  196. font-size: 9px;
  197. border-width: 1px;
  198. }
  199. .statusbar {
  200. font-family: "Tahoma", "Verdana";
  201. font-size: 9px;
  202. color: #999999;
  203. padding-left: 3px;
  204. }
  205. .button {
  206. border: 1px outset;
  207. text-align: center;
  208. }
  209. .navframe {
  210. padding: 5px;
  211. }
  212. -->
  213. </style>
  214. </head>
  215. <body>
  216. <div id="assist" style="position:absolute; left:15px; top:68px; width:185px; z-index:1;display:none;" class="win" onMouseDown="MM_dragLayer('assist','',0,0,150,18,true,false,-1,-1,-1,-1,15,68,100,'',false,'')">
  217.   <table width="180" border="1" cellpadding="0" cellspacing="0">
  218.     <tr>
  219.       <td class="caption">SeekAssist</td>
  220.       <td width="14" align="center"><a href="#" onclick="with(MM_findObj('assistwin').style)display=display=='none'?'':'none'">
  221.                 %</a></td>
  222.       <td width="14" align="center"><a href="#" onClick="MM_showHideLayers('assist','','hide')">
  223.                 X</a></td>
  224.     </tr>
  225.     <tr id="assistwin">
  226.       <td height="100" colspan="3" bordercolor="#eeeeee"> </td>
  227.     </tr>
  228.   </table>
  229.         <br>
  230. </div>
  231. <script>loadwin('assist')</script>
  232. <div id="rank" style="position:absolute; left:15px; top:194px; width:185px; z-index:1;display:none;" class="win" onMouseDown="MM_dragLayer('rank','',0,0,150,18,true,false,-1,-1,-1,-1,15,194,100,'',false,'')">
  233.   <table width="180" border="1" cellpadding="0" cellspacing="0">
  234.     <tr>
  235.       <td class="caption">SeekRank</td>
  236.       <td width="14" align="center"><a href="#" onclick="with(MM_findObj('rankwin').style)display=display=='none'?'':'none'">
  237.                 %</a></td>
  238.       <td width="14" align="center"><a href="#" onClick="MM_showHideLayers('assist','','inherit','rank','','hide')">
  239.                 X</a></td>
  240.     </tr>
  241.     <tr id="rankwin">
  242.       <td height="100" colspan="3" bordercolor="#eeeeee"> </td>
  243.     </tr>
  244.   </table>
  245.   <br>
  246. </div>
  247. <script>setTimeout("loadwin('rank')",500)</script>
  248. <div id="mycolor" style="position:absolute; left:15px; top:320px; width:185px; z-index:1;display:none;" class="win" onMouseDown="MM_dragLayer('mycolor','',0,0,150,18,true,false,-1,-1,-1,-1,15,320,100,'',false,'')">
  249.   <table width="180" border="1" cellpadding="0" cellspacing="0">
  250.     <tr>
  251.       <td class="caption">MyColor</td>
  252.       <td width="14" align="center"><a href="#" onclick="with(MM_findObj('mycolorwin').style)display=display=='none'?'':'none'">
  253.                 %</a></td>
  254.       <td width="14" align="center"><a href="#" onClick="MM_showHideLayers('mycolor','','hide')">
  255.                 X</a></td>
  256.     </tr>
  257.     <tr id="mycolorwin">
  258.       <td height="100" colspan="3" bordercolor="#eeeeee"><table width="100%" border="0" cellspacing="0" cellpadding="2">
  259.         <tr>
  260.           <td align="center"><a href="#" onclick="cs('#00CCFF','#f6f6f6','#eeeeee')">
  261.                         Default</a></td>
  262.         </tr>
  263.         <tr>
  264.           <td align="center"><a href="#" onclick="cs('red','#eeccee','#eeddee')">
  265.                         StyleSheet#1</a></td>
  266.         </tr>
  267.         <tr>
  268.           <td align="center"><a href="#" onclick="cs('#99ccff','#eeeeee','#ccddff')">
  269.                         StyleSheet#2</a></td>
  270.         </tr>
  271.         <tr>
  272.           <td align="center"><a href="#" onclick="cs('#ff9999','#ffffff','#ffeeff')">
  273.                         StyleSheet#3</a></td>
  274.         </tr>
  275.         <tr>
  276.           <td align="center"><a href="#" onclick="cs('skyblue','#eeeeee','#99ddff')">
  277.                         StyleSheet#4</a></td>
  278.         </tr>
  279.         <tr>
  280.           <td align="center"><a href="#" onclick="cs('#009900','#eeffee','#ddffdd')">
  281.                         StyleSheet#5</a></td>
  282.         </tr>
  283.       </table></td>
  284.     </tr>
  285.   </table>
  286.   <br>
  287. </div>
  288. <script>setTimeout("loadwin('mycolor')",1000)</script>
  289. <div id="results" style="position:absolute; left:204px; top:68px; width:575px; z-index:1;display:none;" class="win" onMouseDown="MM_dragLayer('results','',0,0,400,18,true,false,-1,-1,-1,-1,204,68,50,'',false,'')">
  290.   <table width="570" border="1" cellpadding="0" cellspacing="0">
  291.     <tr>
  292.       <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
  293.           <tr>
  294.             <td class="caption">Results</td>
  295.             <td width="12" class="button"><a href="#" onClick="with(MM_findObj('resultswin').style)display=display=='none'?'':'none'">
  296.                         %</a></td>
  297.             <td width="12" class="button"><a href="#" onClick="MM_showHideLayers('results','','inherit')">
  298.                         X</a></td>
  299.           </tr>
  300.       </table></td>
  301.     </tr>
  302.     <tr>
  303.       <td height="20" bordercolor="#eeeeee"><input name="url" type="text" value="http://www.google.com/search?q=ezlee" size="100">
  304.       <a href="#" onclick="mainframe.location=url.value">Search</a></td>
  305.     </tr>
  306.     <tr id="resultswin">
  307.       <td height="318" valign="top" class="navframe"><aiframe name="mainframe" id="mainframe" src="http://www.google.com/search?q=ezlee" width="100%" height="100%" frameborder="0" scrolling="auto"><font color="#FF0000">
  308.                 Welcome!</font></aiframe></td>
  309.     </tr>
  310.     <tr>
  311.       <td height="14" class="statusbar">Ready!</td>
  312.           </tr>
  313.   </table>
  314.   <br>
  315. </div>
  316. <script>setTimeout("loadwin('results')",2000)</script>
  317. </body>
  318. </html>
複製代碼

 

臉書網友討論
發表於 2013-11-13 01:09:28 | 顯示全部樓層
這個帖不错!!!!!  

版主招募中

您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2016-12-9 06:32 , Processed in 0.052777 second(s), 18 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表