我要实现一个像webqq聊天框一样的一个可以拖动的层,
   在网上找到一个例子:http://www.workcss.com/jsdemo/4/index.html  有这样一个问题,拖拽的时候在 非IE浏览器 下,层里面的文字会加上蓝色背景变成选中状态(其他层的文字也会),怎么能让他不选中呢?  不好解决的话,推荐一个更好的拖动层的实现方案也行,谢谢各位大虾了

解决方案 »

  1.   

    你给层加个span标题栏,只有这个标题栏可以拖拽就没有你说的问题了
      

  2.   

    你试试这个:
    <html>
    <head>
    <title>zsqsc,Look! </title>
    <style>
    body,div{margin-left:0px;margin-top:0px;}
    #canbemoved_div{ 
      position:absolute;
      background-color:#fff;
      z-index:999;
      left:100px; top:100px; width:500px;  height:1px;
      clear:both;display:block; height:1px;
    }#canbemoved_title_div{
      background-color:#bbb;
      border-bottom:solid #333;
      width:500px;  height:25px;
      color:red
    }
    #canbemoved_content_div { 
      padding:10px;
      border: 1px solid #ccc;
    }
    /*圆角*/
    .m4,.m3,.m2,.m1{border-left:1px solid #ccc;border-right:1px solid #ccc;background:#ccc;display:block; height:1px; overflow:hidden;}
    .m4 {margin:0 4px; background:#eee; }
    .m3 { margin:0 3px;}
    .m2 { margin:0 2px; }
    .m1 { margin:0 1px; }</style>
    <script type="text/javascript">
    var bStartDrag=false, dx=0, dy=0;
    function $(id){return document.getElementById(id);}function beginDrag(e,o){
      bStartDrag=true;  o.style.cursor='move';  
      e=e||window.event;
      var _x=e.clientX||e.pageX, _y=e.clientY||e.pageY; objDrag=o.parentNode;
      dx=_x-parseInt(objDrag.offsetLeft);
      dy=_y-parseInt(objDrag.offsetTop);
    if(document.addEventListener){
    objDrag.addEventListener("mousemove",_moveHandler,true);
    objDrag.addEventListener("mouseup",_upHandler,true);
    }
    else if(document.attachEvent){
    objDrag.attachEvent("onmousemove",_moveHandler);
    objDrag.attachEvent("onmouseup",_upHandler);
    }      
    function _upHandler(){
    if(document.removeEventListener){
    objDrag.removeEventListener("mouseup",_upHandler,true);
    objDrag.removeEventListener("mousemove",_moveHandler,true);
    }
    else{
    objDrag.detachEvent("onmouseup",_upHandler);
    objDrag.detachEvent("onmousemove",_moveHandler);
    }
    stopDrag();
    }

    function _moveHandler(e){
      e=e||window.event;
      if(bStartDrag){
        with(objDrag){
    var myX=e.clientX-dx, myY=e.clientY-dy;
          style.left=myX+'px';   style.top=myY+'px';
    dx=e.clientX-offsetLeft;
    dy=e.clientY-offsetTop;  
       }
      }
    }
    function stopDrag(){
      $('canbemoved_title_div').style.cursor='default';
    }

    }
    </script>
    </head>
    <body>
    <div id="canbemoved_div">
     <span class="m4"></span>
     <span class="m3"></span>
     <span class="m2"></span> <span class="m1"></span>
    <div id='canbemoved_title_div' onmousedown="beginDrag(event,this);">
      <span style'color:red'>标题栏</span>
    </div>
    <div id='canbemoved_content_div'>
      <p>
    我要实现一个像webqq聊天框一样的一个可以拖动的层,
      在网上找到一个例子:http://www.workcss.com/jsdemo/4/index.html  有这样一个问题,拖拽的时候在 非IE浏览器 下,层里面的文字会加上蓝色背景变成选中状态(其他层的文字也会),怎么能让他不选中呢?  不好解决的话,推荐一个更好的拖动层的实现方案也行,谢谢各位大虾了
    </p>
    </div>
    </div>
    </body></html> 
      

  3.   


    不太明白你说的什么意思?要解决的问题是,我的拖拽响应区域是一个div层,里面包含各种标签,拖动时网站的所有span内容都可能成选中状态,怎么样让它不选中呢?
      

  4.   

    doDrag3
    函数的里面加上
    window.getSelection&&window.getSelection().removeAllRanges();
    每次移动的时候都会清空选中也可以看看我这个
    不过图片都木有了  木有了
    http://www.cnblogs.com/wtcsy/archive/2010/02/25/vv.html
      

  5.   

    很好解决的问题,body 里加上 onselectstart= "return false" 但是这样一来所有文本都不能选中,这个要注意
      

  6.   

    不太明白为什么你不太明白我说的意思,哈哈。
    【我的拖拽响应区域是一个div层,里面包含各种标签,拖动时网站的所有span内容都可能成选中状态】:
    我的建议是不让这个整个DIV成为拖拽响应区域,而是加个标题栏。就像拖拽程序窗口一样,只能拖动标题栏才可以移动。具体的,2楼的例子已经展示了