隨筆 - 154  文章 - 60  trackbacks - 0
          <2007年10月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          聲明:

          該blog是為了收集資料,認(rèn)識(shí)朋友,學(xué)習(xí)、提高技術(shù),所以本blog的內(nèi)容除非聲明,否則一律為轉(zhuǎn)載!!

          感謝那些公開(kāi)自己技術(shù)成果的高人們!!!

          支持開(kāi)源,尊重他人的勞動(dòng)!!

          常用鏈接

          留言簿(3)

          隨筆分類(lèi)(148)

          隨筆檔案(143)

          收藏夾(2)

          其他

          學(xué)習(xí)(技術(shù))

          觀察思考(非技術(shù))

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          例子一
          ===================================================

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          " <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
          <title>drag layer</title>
          <style>
          body,table{color:#000000;
              font-size:12px;
          }
          div.div_one{}
          .dragBar{color:#FFFFFF;
              font-weight:bold}
          </style>
          <script language="javascript" defer>
          /*written by
          joelee@51js
          */
              var tmpElement=null;
              var dragElement=null;
              var downX,downY,tmp_o_x,tmp_o_y;
              var refElement=null;
              var dragActive=0;
              var draging=0;
          function readyDrag(){
              dragActive=1;
              if(event.srcElement.tagName!="DIV")
                  return;
              dragElement=event.srcElement.parentNode;
              tmpElement=dragElement.cloneNode(true);
              tmpElement.style.filter="alpha(opacity=90)";
              tmpElement.style.zIndex=2;
              dragElement.style.zIndex=1;
              tmpElement.style.position="absolute";
              if(dragElement.parentNode.tagName!="BODY"){
                  dragElement.style.left=dragElement.offsetLeft+dragElement.parentNode.style.pixelLeft;
                  dragElement.style.top=dragElement.offsetTop+dragElement.parentNode.style.pixelTop;
              }
              downX=event.clientX;
              downY=event.clientY;
              tmp_o_x=dragElement.style.pixelLeft;
              tmp_o_y=dragElement.style.pixelTop;
              tmpElement.style.visibility="hidden";
              document.body.appendChild(tmpElement);
              document.onmousemove=startDrag;
              }
              document.onmouseup=endDrag;
          function startDrag(){
              if(dragActive==1&&event.button==1&&dragElement!=null&&tmpElement!=null){
                  tmpElement.style.visibility="visible";
                  tmpElement.style.left=tmp_o_x+event.clientX-downX;
                  tmpElement.style.top=tmp_o_y+event.clientY-downY;
                  dragElement.style.backgroundColor="#CCCCCC";
                  document.body.style.cursor="move";
                  draging=1;
              }
          }
          function endDrag(){
              if(dragActive==1&&tmpElement!=null){
                  if(draging==1){
                      dragElement.removeNode(true);
                      draging=0;
                  }
                  tmpElement.style.filter="alpha(opacity=100)";
                  tmpElement.style.zIndex=1;
                  document.body.style.cursor="default";
                  if(refElement!=null&&refElement.parentNode!=null&&refElement.parentNode.tagName!="BODY"){
                      tmpElement.style.width=refElement.parentNode.style.width;
                      tmpElement.style.position="";
                      refElement.parentNode.insertBefore(tmpElement,refElement);
                  }
              }
              dragElement=null;
              tmpElement=null;
              dragActive=0;
          }
          function readyInsert(){
              if(dragActive==1){
                  var element=event.srcElement;
                  if(element==dragElement)return;
                  if(element.tagName!="DIV")
                      return;
                  if(element.className=="dragBar"||element.className=="textSheet"||element.className=="blankBar")
                      element=element.parentNode;
                  element.style.backgroundColor="#CCCCCC";
                  element.style.filter="alpha(opacity=50)";
                  refElement=element;
              }
          }
          function failInsert(){
              var element=event.srcElement;
              if(element.tagName!="DIV")
                  return;
              try{
                  if(element.className=="dragBar"||element.className=="textSheet"||element.className=="blankBar")
                      element=element.parentNode;
              }catch(e){}
              element.style.filter="alpha(opacity=100)";
              element.style.backgroundColor="#FFFFFF";
              refElement=null;
          }
          document.onselectstart=function(){return false}
          </script>
          </head>

          <body>
          <div id="div_one" class="div_one" style="position:absolute; left:116px; top:137px; width:433px; z-index:1; background-color: #FFFFFF; layer-background-color: #FFFFFF;" onMouseOver="readyInsert()" onMouseOut="failInsert()">
            <div onMouseDown="readyDrag()" style="cursor:move; border:1px solid #996666; background-color:#996666; height:20px" name="dragDIV" class="dragBar"><img src="snap_icon.gif" width="16" height="16">Window</div>
          <div class="textSheet" style="border:1px solid #996666;">Content<br>
            Content<br>
            Content<br>
            Content  <br>
          </div>
          <div class="blankBar" style="height:10px"></div></div>
          <div id="grid1" style="position:absolute; left:534px; top:37px; width:336px; height:15px; z-index: 100; visibility: visible;">
            <div style="height:20px;z-index:2;" onMouseOver="readyInsert()" onMouseOut="failInsert();">把層拖動(dòng)到這兒</div>
          </div>
          <div id="grid2" style="position:absolute; left:20px; top:40px; width:494px; height:15px; z-index: 100; visibility: visible;">
            <div style="height:20px;z-index:2; background-image:url()" onMouseOver="readyInsert()" onMouseOut="failInsert();">把層拖動(dòng)到這兒</div>
          </div>
          <div id="div_one" class="div_one" style="position:absolute; left:204px; top:277px; width:433px; z-index:1; background-color: #FFFFFF; layer-background-color: #FFFFFF;" onMouseOver="readyInsert()" onMouseOut="failInsert()">
            <div onMouseDown="readyDrag()" style="cursor:move; border:1px solid #996666; background-color:#996666; height:20px" name="dragDIV" class="dragBar"><img src="snap_icon.gif" width="16" height="16">BBS</div>
            <div class="textSheet" style="border:1px solid #996666;">Content</div>
            <div class="blankBar" style="height:10px"></div>
          </div>
          <div id="div_one" class="div_one" style="position:absolute; left:561px; top:195px; width:433px; z-index:1; background-color: #FFFFFF; layer-background-color: #FFFFFF;" onMouseOver="readyInsert()" onMouseOut="failInsert()">
            <div onMouseDown="readyDrag()" style="cursor:move; border:1px solid #996666; background-color:#996666; height:20px" name="dragDIV" class="dragBar"><img src="snap_icon.gif" width="16" height="16">Log</div>
            <div class="textSheet" style="border:1px solid #996666;">Content<br>
              Content<br>
              Content    <br>
            Content<br>
          </div>
            <div class="blankBar" style="height:10px"></div>
          </div>
          <div id="div_one" class="div_one" style="position:absolute; left:438px; top:74px; width:433px; z-index:1; background-color: #FFFFFF; layer-background-color: #FFFFFF;" onMouseOver="readyInsert()" onMouseOut="failInsert()">
            <div onMouseDown="readyDrag()" style="cursor:move; border:1px solid #996666; background-color:#996666; height:20px" name="dragDIV" class="dragBar"><img src="snap_icon.gif" width="16" height="16">Worker</div>
            <div class="textSheet" style="border:1px solid #996666;">Content</div>
            <div class="blankBar" style="height:10px"></div>
          </div>
          <div id="div_one" class="div_one" style="position:absolute; left:206px; top:406px; width:433px; z-index:1; background-color: #FFFFFF; layer-background-color: #FFFFFF;" onMouseOver="readyInsert()" onMouseOut="failInsert()">
            <div onMouseDown="readyDrag()" style="cursor:move; border:1px solid #996666; background-color:#996666; height:20px" name="dragDIV" class="dragBar"><img src="snap_icon.gif" width="16" height="16">Tools</div>
            <div class="textSheet" style="border:1px solid #996666;">Content</div>
            <div class="blankBar" style="height:10px"></div>
          </div>
          </body>
          </html>

          例子二

          ================================================================

          <html>
          <head>
          <title>DRAG the DIV</title>
          <style>
          *{font-size:12px}
          .dragTable{
              font-size:12px;
              border-top:1px solid #3366cc;
              margin-bottom: 10px;
              width:100%;
              background-color:#FFFFFF;
          }
          .dragTR{
              cursor:move;
              color:#7787cc;
              background-color:#e5eef9;
          }
          td{vertical-align:top;}
          #parentTable{
              border-collapse:collapse;
              letter-spacing:25px;
          }
          </style>
          <script defer>
          /****JoeLee************E-MAIL:hktx@163.com****QQ:48293707*****11:09 2006-2-9******/
              var draged=false;
              tdiv=null;
          function dragStart(){
              ao=event.srcElement;
              if((ao.tagName=="TD")||(ao.tagName=="TR"))ao=ao.offsetParent;
              else return;
              draged=true;
              tdiv=document.createElement("div");
              tdiv.innerHTML=ao.outerHTML;
              tdiv.style.display="block";
              tdiv.style.position="absolute";
              tdiv.style.filter="alpha(opacity=70)";
              tdiv.style.cursor="move";
              tdiv.style.width=ao.offsetWidth;
              tdiv.style.height=ao.offsetHeight;
              tdiv.style.top=getInfo(ao).top;
              tdiv.style.left=getInfo(ao).left;
              document.body.appendChild(tdiv);
              lastX=event.clientX;
              lastY=event.clientY;
              lastLeft=tdiv.style.left;
              lastTop=tdiv.style.top;
              try{
                  ao.dragDrop();   
              }catch(e){}
          }
          function draging(){//重要:判斷MOUSE的位置
              if(!draged)return;
              var tX=event.clientX;
              var tY=event.clientY;
              tdiv.style.left=parseInt(lastLeft)+tX-lastX;
              tdiv.style.top=parseInt(lastTop)+tY-lastY;
              for(var i=0;i<parentTable.cells.length;i++){
                  var parentCell=getInfo(parentTable.cells[i]);
                  if(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){
                      var subTables=parentTable.cells[i].getElementsByTagName("table");
                      if(subTables.length==0){
                          if(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){
                              parentTable.cells[i].appendChild(ao);
                          }
                          break;
                      }
                      for(var j=0;j<subTables.length;j++){
                          var subTable=getInfo(subTables[j]);
                          if(tX>=subTable.left&&tX<=subTable.right&&tY>=subTable.top&&tY<=subTable.bottom){
                              parentTable.cells[i].insertBefore(ao,subTables[j]);
                              break;
                          }else{
                              parentTable.cells[i].appendChild(ao);
                          }   
                      }
                  }
              }
          }

          function dragEnd(){
              if(!draged)return;
              draged=false;
              mm=ff(150,15);
          }
          function getInfo(o){//取得坐標(biāo)
              var to=new Object();
              to.left=to.right=to.top=to.bottom=0;
              var twidth=o.offsetWidth;
              var theight=o.offsetHeight;
              while(o!=document.body){
                  to.left+=o.offsetLeft;
                  to.top+=o.offsetTop;
                  o=o.offsetParent;
              }
                  to.right=to.left+twidth;
                  to.bottom=to.top+theight;
              return to;
          }
          function ff(aa,ab){//從GOOGLE網(wǎng)站來(lái),用于恢復(fù)位置
              var ac=parseInt(getInfo(tdiv).left);
              var ad=parseInt(getInfo(tdiv).top);
              var ae=(ac-getInfo(ao).left)/ab;
              var af=(ad-getInfo(ao).top)/ab;
              return setInterval(function(){if(ab<1){
                                      clearInterval(mm);
                                      tdiv.removeNode(true);
                                      ao=null;
                                      return
                                  }
                              ab--;
                              ac-=ae;
                              ad-=af;
                              tdiv.style.left=parseInt(ac)+"px";
                              tdiv.style.top=parseInt(ad)+"px"
                          }
          ,aa/ab)
          }
          function inint(){//初始化
              for(var i=0;i<parentTable.cells.length;i++){
                  var subTables=parentTable.cells[i].getElementsByTagName("table");
                  for(var j=0;j<subTables.length;j++){
                      if(subTables[j].className!="dragTable")break;
                      subTables[j].rows[0].className="dragTR";
                      subTables[j].rows[0].attachEvent("onmousedown",dragStart);
                      subTables[j].attachEvent("ondrag",draging);
                      subTables[j].attachEvent("ondragend",dragEnd);
                  }
              }
          }
          inint();
          </script>
          </head>
          <body>
          <table border="0" cellpadding="0" cellspacing="10" width="100%" height=500 id="parentTable">
          <tr >
              <td width="25%" valgin="top">
                  <table border=0 class="dragTable" cellspacing="0">
                      <tr>
                          <td><b>GMAIL</b></td>
                      </tr>
                      <tr>
                          <td>暫時(shí)無(wú)法顯示GMAIL內(nèi)容</td>
                      <tr>
                  </table><table border=0 class="dragTable" cellspacing="0">
                      <tr>
                          <td>新浪體育</td>
                      </tr>
                      <tr>
                          <td>解剖威隊(duì)獨(dú)門(mén)利器FW28 2萬(wàn)轉(zhuǎn)引擎匹配超級(jí)變速器頒獎(jiǎng):辛吉斯欣喜能以冠軍起步 印度搭檔創(chuàng)下紀(jì)錄法新社前瞻冬奧短道速滑:中韓唱主角 美加施冷箭</td>
                      <tr>
                  </table><table border=0 class="dragTable" cellspacing="0">
                      <tr>
                          <td>焦點(diǎn)</td>
                      </tr>
                      <tr>
                          <td>京廣線中斷4小時(shí)20臨客返漢晚點(diǎn)
          中國(guó)新聞網(wǎng)-湖北分社 - 所有 235 相關(guān)報(bào)道 »哈馬斯已有總理人選
          解放日?qǐng)?bào)報(bào)業(yè)集團(tuán) - 所有 489 相關(guān)報(bào)道 »陳水扁是兩岸關(guān)系麻煩制造者
          武漢晨報(bào) - 所有 179 相關(guān)報(bào)道 »</td>
                      <tr>
                  </table>
              </td>
              <td width="25%">
                  <table border=0 class="dragTable" cellspacing="0">
                      <tr>
                          <td>中關(guān)村在線</td>
                      </tr>
                      <tr>
                          <td>新年行情速遞 雙敏板卡低價(jià)推薦 終于等到了,映泰6600GT一降降一百 羅技G15游戲鍵盤(pán)熱力促銷(xiāo),代購(gòu)價(jià)僅529元 </td>
                      <tr>
                  </table></td>
              <td width="25%">
                  <table border=0 class="dragTable" cellspacing="0">
                      <tr>
                          <td>網(wǎng)易商業(yè)</td>
                      </tr>
                      <tr>
                          <td>上海GDP增幅去年出現(xiàn)回落應(yīng)對(duì)反傾銷(xiāo) 中國(guó)鞋企聯(lián)手對(duì)抗歐盟尹家緒操盤(pán)南方汽車(chē) 長(zhǎng)安謀求曲線整體境外上市</td>
                      <tr>
                  </table>
              </td>
          </tr>
          </table>
          </body>
          </html>

          posted on 2007-10-09 09:19 lk 閱讀(245) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): ajax&js
          主站蜘蛛池模板: 喜德县| 于都县| 惠来县| 九台市| 揭阳市| 灵川县| 沁阳市| 南木林县| 綦江县| 靖宇县| 永川市| 永春县| 南安市| 黔江区| 施甸县| 深州市| 虞城县| 华宁县| 米易县| 婺源县| 石楼县| 沁源县| 个旧市| 华容县| 竹溪县| 瑞安市| 财经| 丰都县| 宿松县| 当雄县| 宜阳县| 正蓝旗| 县级市| 五河县| 三都| 广饶县| 郁南县| 彭山县| 任丘市| 肇庆市| 精河县|