html div的移动

var i=1;
function enableDrag(o)
{
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.onmousedown = function(a) 
    {
    this.style.zIndex = 100+i;
        i++;
        this.style.cursor = "move"; 
        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 the mousedown Event is in close button, close the layer and quit
        if ((parseInt(o.style.width) - 30)< x && x < (parseInt(o.style.width) - 10)
        && (10 < y && y < 30))
        {
        setFormInvisible(o.id);
        return;
        }                 
        if(o.setCapture) 
            o.setCapture(); 
        else if(window.captureEvents) 
            window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP); 

        d.onmousemove = function(a) 
        { 
            if(!a)a=window.event; 
            o.style.left = a.clientX+document.body.scrollLeft-x; 
            o.style.top = a.clientY+document.body.scrollTop-y; 
            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";
        } 
    }


function disableDrag(o)

//alert(o);
    if (typeof o == "string")  o = document.getElementById(o); 
    o.onmousedown = null;
}
// End: Functions for enabling/disabling drag and drop

你可能感兴趣的:(html)