views:

108

answers:

2

Hi all,

I have a html page as below :

<table cellpadding="1" cellspacing="1" border="1">
        <tr>
            <td id="abc">
                <div style="height: 23px; overflow: hidden; position: relative; height: 70px; width: 70px;
                    background-color: red" valign="top" id="dragable3">
                    <a style="color: white" class="CalendarPlus-Item-2010311422" title="" href="#"><font
                        color="white">New Item</font></a></div>
            </td>
            <td>
                <div id="4" style="width: 80px; height: 80px;">
            </td>
            <td>
                <div id="5" style="width: 80px; height: 80px;">
            </td>
        </tr>
        <tr>
            <td>
                <div id="8" style="width: 80px; height: 80px;">
            </td>
            <td>
                <div id="7" style="width: 80px; height: 80px;">
            </td>
            <td>
                <div id="6" style="width: 80px; height: 80px;">
            </td>
        </tr>
    </table>

and the jquery.js and the file javascript :

var DragHandler = {

// private property.
_oElem: null,

// public method. Attach drag handler to an element.
attach: function(oElem) {
    oElem.onmousedown = DragHandler._dragBegin;
    return oElem;
},

// private method. Begin drag process.
_dragBegin: function(e) {
    var oElem = DragHandler._oElem = this;

    if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '0px'; }
    if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '0px'; }

    var x = parseInt(oElem.style.left);
    var y = parseInt(oElem.style.top);

    e = e ? e : window.event;
    oElem.mouseX = e.clientX;
    oElem.mouseY = e.clientY;

    document.onmousemove = DragHandler._drag;
    document.onmouseup = DragHandler._dragEnd;
    return false;
},

// private method. Drag (move) element.
_drag: function(e) {
    var oElem = DragHandler._oElem;

    var x = parseInt(oElem.style.left);
    var y = parseInt(oElem.style.top);

    e = e ? e : window.event;
    oElem.style.left = x + (e.clientX - oElem.mouseX) + 'px';
    oElem.style.top = y + (e.clientY - oElem.mouseY) + 'px';

    oElem.mouseX = e.clientX;
    oElem.mouseY = e.clientY;

    return false;
},

// private method. Stop drag process.
_dragEnd: function() {
    document.onmousemove = null;
    document.onmouseup = null;
    DragHandler._oElem = null;

},

_onPostBack: function(form, ehandle, arg) {
    var theForm = document.forms[form];
    if (!theForm) {
        theForm = document.aspnetForm;
    }
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
        theForm.__EVENTTARGET.value = ehandle;
        theForm.__EVENTARGUMENT.value = arg;
        theForm.submit();
    }
}
}

DragHandler.attach(document.getElementById('dragable3'));

How do I get the Element under the div (id="dragable3") that is moved. Example : I moved the div tag (id="dragable3") from the td tag (id=abc) to the div tag (id="6"). How do we get the div tag(id="6") after mouseup ?

Thanks ,

Phong Dang.

A: 

Write the mouse event for div id=6 . use onmouseup or onmouseover . There by you can catch the mouse events and do the require stuffs.

pavun_cool
A: 

we cannot set onmouseover or onmouseup for the div (id=6) because this event cannot fire.

Phong Dang

related questions