J
jon
Hello,
I'm trying to experiment with some javascript to do some custom
dragdrop handling. I wish to use the onMouseDown event to trigger the
start of my drag, and onMouseup for a potentential drop. I hope to
turn on the onmouseup only in onmousedown. And eventually go one step
further and incorporate onmousemove for a true drag workflow.
I'm running into a problem however, where after mousedown, mouseup will
not fire when I release the mouse button. It will however fire if I
click again. So the event isn't being tracked until I release the
mouse the first time apparently. Which ruins my dragDrop of course.
Below is the code. You can see a move() method that would incorporate
onmousemove, but for the most basic test I'm just using beginDrag and
endDrag.
Any ideas why onmouseup won't fire until I release the button, then
click again?
thanks
--------------
<table cellpadding="0" cellspacing="5" border="1">
<tr id="contentTr1">
<td id="image_1_td" >
<img id="image_1_img" src="cat1.jpg"
onMouseDown="beginDrag(event, this, this.id)">
</td>
<td id="image_2_td">
<img id="image_2_img" src="cat2.jpg"
onMouseDown="beginDrag(event, this, this.id)">
</td>
</tr>
</table>
--------------
var beginX = null;
var beginY = null;
function beginDrag(event, obj, id) {
beginX = event.clientX;
beginY = event.clientY;
window.status = 'beginDrag';
top.drag_id = id;
//document.onmousemove = function() { move(event, obj, id); };
document.onmouseup = function() {
window.status='onmouseup frame1';
endDrag(event);
top.frame1.document.onmousemove=null;
top.frame1.document.onmouseup=null;
top.drag_id = null;
};
}
function move(event, obj, id) {
if(beginX == null){ return; }
window.status = 'drag started: ' + event.clientX + ', ' +
event.clientY + ', onmouseup set and waiting...';
top.drag_id = id;
document.onmouseup = function() {
window.status='onmouseup frame1';
top.frame1.document.onmousemove=null;
top.frame1.document.onmouseup=null;
top.drag_id = null;
};
}
function endDrag(event) {
if(top.drag_id != null){
window.status = 'drop handled: ' + top.drag_id;
return true;
} else {
return false;
}
}
I'm trying to experiment with some javascript to do some custom
dragdrop handling. I wish to use the onMouseDown event to trigger the
start of my drag, and onMouseup for a potentential drop. I hope to
turn on the onmouseup only in onmousedown. And eventually go one step
further and incorporate onmousemove for a true drag workflow.
I'm running into a problem however, where after mousedown, mouseup will
not fire when I release the mouse button. It will however fire if I
click again. So the event isn't being tracked until I release the
mouse the first time apparently. Which ruins my dragDrop of course.
Below is the code. You can see a move() method that would incorporate
onmousemove, but for the most basic test I'm just using beginDrag and
endDrag.
Any ideas why onmouseup won't fire until I release the button, then
click again?
thanks
--------------
<table cellpadding="0" cellspacing="5" border="1">
<tr id="contentTr1">
<td id="image_1_td" >
<img id="image_1_img" src="cat1.jpg"
onMouseDown="beginDrag(event, this, this.id)">
</td>
<td id="image_2_td">
<img id="image_2_img" src="cat2.jpg"
onMouseDown="beginDrag(event, this, this.id)">
</td>
</tr>
</table>
--------------
var beginX = null;
var beginY = null;
function beginDrag(event, obj, id) {
beginX = event.clientX;
beginY = event.clientY;
window.status = 'beginDrag';
top.drag_id = id;
//document.onmousemove = function() { move(event, obj, id); };
document.onmouseup = function() {
window.status='onmouseup frame1';
endDrag(event);
top.frame1.document.onmousemove=null;
top.frame1.document.onmouseup=null;
top.drag_id = null;
};
}
function move(event, obj, id) {
if(beginX == null){ return; }
window.status = 'drag started: ' + event.clientX + ', ' +
event.clientY + ', onmouseup set and waiting...';
top.drag_id = id;
document.onmouseup = function() {
window.status='onmouseup frame1';
top.frame1.document.onmousemove=null;
top.frame1.document.onmouseup=null;
top.drag_id = null;
};
}
function endDrag(event) {
if(top.drag_id != null){
window.status = 'drop handled: ' + top.drag_id;
return true;
} else {
return false;
}
}