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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.