本帖最后由 list8477 于 2010-09-07 17:00:30 编辑

解决方案 »

  1.   

    $(this).parent().mousemove(function(event){//拖父元素看看
                if(_move){
                    var x = event.clientX -_x;
                    var y = event.clientY -_y;
                    $('#'+id).css({top:y,left:x});
                    window.status = 'x:'+x+"\ty:"+y;
                }
            
            }).mouseup(function(){
                _move=false;
            });
      

  2.   

    那为什么偏把该行this替换为document呢.无论document还是父元素,属于父元素内部的两个或更多的子元素肯定是要一起动了,必须分开针对每个子元素本身才对.
      

  3.   

    看下我很久以前写的,,是何等效率...CPU占用率..<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> New Document </TITLE>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></HEAD> <BODY style="height:800px;">
    <div id="tee" style="width:200px; height:200px; background:#f00; position:absolute; cursor:move"></div>
    <script type="text/javascript">
    var tee=document.getElementById('tee');

    tee.onmousedown=function(e){
    e=e || event;
    start(e,this);
    e.cancelBubble=true;
    return false;
    }
    function start(e,o)
    {
    var i,
    x,
    y;
    i=0;
    x=e.screenX-o.offsetLeft;
    y=e.screenY-o.offsetTop;

    if(window.addEventListener)
    {
    window.document.addEventListener('mousemove',moving,false)
    window.document.addEventListener('mouseup',end,false)
    }else{
    window.document.attachEvent('onmousemove',moving)
       window.document.attachEvent('onmouseup',end)   }
    function moving(e)
    {
    if(i++^6)//计数器, 如果i=6 则 i^6==0
    return;
    o.style.left=(e.screenX-x)+'px';
    o.style.top=(e.screenY-y)+'px';
    i=0;

    } function end(e)
    {
    if(window.addEventListener)
    {
    window.document.removeEventListener('mousemove',moving,false);
    document.removeEventListener('mouseup',arguments.callee,false);
    }else{
    window.document.detachEvent('onmousemove',moving);
    window.document.detachEvent('onmouseup',arguments.callee);  }

    window.document.body.focus() // ff 3.0
    }

    }// end start
    </script>
     </BODY>
    </HTML>
      

  4.   

    其实拖动取偏移值会更快....这个是仓库里的html页了..忘了把内部函数弄出来了...
      

  5.   


    var popupMove=function(obj){
    var mobj=obj.parent();
    obj.mousedown(function(e){
    if(this.setCapture){
    this.setCapture();
    }else if(window.captureEvents){
    window.captureEvents(Event.mousemove|Event.mouseup);
    }
    posX = e.clientX - mobj.offset().left;
    posY = e.clientY - mobj.offset().top;
    $(this).mousemove(function(e){
    mobj.css({
    "left":(e.clientX - posX) + "px",
    "top":(e.clientY - posY) + "px"
    });

    })
    });
    obj.mouseup(function(){
    if(this.releaseCapture){
    this.releaseCapture();
    }else if(window.captureEvents){
    window.captureEvents(Event.mousemove|Event.mouseup);
    }
    $(this).unbind("mousemove");
    })
    }
      

  6.   

    (function($){
        $.fn.drag=function(){
            var _move = false;
    var _x,_y;
            $(this).mousedown(function(event){
                _move = true;
                _x = event.clientX;
                _y = event.clientY;
            });
            
            $(this).mousemove(function(event){/*如果该行this替换为document后,
    拖拽效果很好,但是出现的问题是:当我同时为两个对象添加拖拽动作后,问
    题就出现了,不论拖动哪一个两个都动。反过来拖拽起来很卡,但是不会两个
    对象同时都动。帮忙看看到底该怎么处理?[/color]*/
                if(_move){
                    var x = event.clientX -_x;
                    var y = event.clientY -_y;
                    $(this).css({top:y+$(this).position().top,left:x+$(this).position().left});
                    _x = event.clientX;
                _y = event.clientY;
                    window.status = 'x:'+x+"\ty:"+y;
                }
            
            }).mouseup(function(){
                _move=false;
            });;
        }
              
    })(jQuery);
    在你的drag.js基础上改的,你试试。