Jump to content

Drag and Drop - Almost There


jxrd

Recommended Posts

Hello,

 

I've been working on a drag and drop thing, and it works fine in IE, but not in FF, which is odd. It's normally the other way round.

 

For some reason, Firefox just moves it once...it's weird. Test out my script and you'll see what I mean:

<script type="text/javascript">
function drag(element, event)
{
//init drag
document.body.onmousemove = function()
{
	drag_Move(element, event);
}
document.body.onmouseup = function()
{
	document.body.onmousemove = null;
}
}
function drag_Move(element, event)
{
with(element)
{
	style.top = (event.pageY) ? event.pageY+'px' : event.clientY + document.body.scrollTop+'px';
	style.left = (event.pageX) ? event.pageX +'px' : event.clientX + document.body.scrollTop+'px';
}
}
</script>
<body>
<a id="drag" style="position: absolute;" onmousedown="drag(this, event);">yo</a>

I've been working at this for ages, and I can't get it to work. Any help would be greatly appreciated.

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/159926-drag-and-drop-almost-there/
Share on other sites

!!!!

 

I think I figured out what it is. I'm calling the function with an onmousedown event. I think maybe the mousemove event not being passed is causing the problem. For example, if you add this to the code:

<body style="height: 1000px;" onclick="drag(document.getElementById('drag'), event);">

it works fine, but obviously it's constantly moving.

 

So yeah, you wouldn't happen to know how to create a mousemove event would you? :)

 

Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.