我现在写了个拖动,但是如果在DIV中加上一个一样大小的图片,图片就无法正常拖动了。没有图片的话可以正常使用
所谓的图片无法正常拖动显示为只能拖动很小一段距离,然后鼠标手势就变成了一个禁止图形,图片不再跟着鼠标移动,这时放开鼠标后图片又跟踪鼠标移动了,但是我需要的是放开鼠标后图片和其父DIV应当不再移动

解决方案 »

  1.   


     function drag(o, s) {            if (typeof o == "string") o = document.getElementById(o);
                o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
                o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
                o.orig_index = o.style.zIndex;            o.onmousedown = function(a) {
                    this.style.cursor = "pointer";
                    //this.style.zIndex = 10000;                var d = document;
                    if (!a) a = window.event;
                    var x = a.clientX + d.body.scrollLeft - o.offsetLeft;
                    var y = a.clientY + d.body.scrollTop - o.offsetTop;                d.ondragstart = "return false;"
                    d.onselectstart = "return false;"
                    d.onselect = "document.selection.empty();"                if (o.setCapture)
                        o.setCapture();
                    else if (window.captureEvents)
                        window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);                d.onmousemove = function(a) {
                        if (!a) a = window.event;
                        var xx = parseInt(a.clientY + document.body.scrollTop - y) - document.body.scrollTop;
                        var yy = parseInt(a.clientX + document.body.scrollLeft - x) - document.body.scrollLeft;                    /****定义移动范围哦******/                    // var topmin = document.getElementById("maxheightpic").offsetTop;
                        // var topmax = document.getElementById("maxheightpic").scrollHeight + document.getElementById("maxheightpic").offsetTop - 30;
                        // var leftmin = document.getElementById("maxheightpic").offsetLeft;
                        // var leftmax = document.getElementById("maxheightpic").offsetLeft + document.getElementById("maxheightpic").offsetWidth - document.getElementById(o.id).offsetWidth;                    o.style.left = a.clientX + document.body.scrollLeft - x + "px";
                        o.style.top = a.clientY + document.body.scrollTop - y + "px";
                        o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
                        o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
                    }
                    d.onmouseup = function() {                             if (o.releaseCapture)
                            o.releaseCapture();
                        else if (window.captureEvents)
                            window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
                        d.onmousemove = null;
                        d.onmouseup = null;
                        d.ondragstart = null;
                        d.onselectstart = null;
                        d.onselect = null;
                        o.style.cursor = "normal";
                        o.style.zIndex = o.orig_index;
                        document.onmousemove = onmousedown;
                    }                if (s) {
                        var orig_scroll = window.onscroll ? window.onscroll : function() { };
                        window.onscroll = function() {
                            orig_scroll();
                            o.style.left = o.orig_x + document.body.scrollLeft;
                            o.style.top = o.orig_y + document.body.scrollTop;
                        }
                    }
                }
            }
      

  2.   

    有个想法,在拖动前把图片的url保存一份,拖动时只拖动div,当停止时再去请求图片